gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant] branch master updated: handle json allocat


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: handle json allocation failures, check MHD response code and log at least
Date: Tue, 04 Jun 2019 00:08:00 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 3b9eff3  handle json allocation failures, check MHD response code and 
log at least
3b9eff3 is described below

commit 3b9eff33d011b1042934f5b57a1baf3f759909f8
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Jun 4 00:07:57 2019 +0200

    handle json allocation failures, check MHD response code and log at least
---
 src/backend/taler-merchant-httpd_pay.c         | 33 ++++++++++++++++++++------
 src/backend/taler-merchant-httpd_responses.c   | 14 ++++++-----
 src/backend/taler-merchant-httpd_tip-pickup.c  | 25 +++++++++++++++----
 src/backend/taler-merchant-httpd_trigger-pay.c |  4 ++--
 4 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_pay.c 
b/src/backend/taler-merchant-httpd_pay.c
index f87d1c8..2764a0c 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -1918,6 +1918,15 @@ begin_transaction (struct PayContext *pc)
       json_t *refunds;
 
       refunds = json_array ();
+      if (NULL == refunds)
+      {
+        GNUNET_break (0);
+        resume_pay_with_error (pc,
+                               MHD_HTTP_INTERNAL_SERVER_ERROR,
+                               TALER_EC_JSON_ALLOCATION_FAILURE,
+                               "could not create JSON array");
+        return;
+      }
       for (unsigned int i=0;i<pc->coins_cnt;i++)
       {
         struct TALER_RefundRequestPS rr;
@@ -1956,13 +1965,23 @@ begin_transaction (struct PayContext *pc)
         }
 
         /* Pack refund for i-th coin.  */
-        json_array_append_new (refunds,
-                               json_pack ("{s:I, s:o, s:o s:o s:o}",
-                                          "rtransaction_id", (json_int_t) 
rtransactionid,
-                                          "coin_pub", 
GNUNET_JSON_from_data_auto (&rr.coin_pub),
-                                          "merchant_sig", 
GNUNET_JSON_from_data_auto (&msig),
-                                          "refund_amount", 
TALER_JSON_from_amount_nbo (&rr.refund_amount),
-                                          "refund_fee", 
TALER_JSON_from_amount_nbo (&rr.refund_fee)));
+        if (0 !=
+            json_array_append_new (refunds,
+                                   json_pack ("{s:I, s:o, s:o s:o s:o}",
+                                              "rtransaction_id", (json_int_t) 
rtransactionid,
+                                              "coin_pub", 
GNUNET_JSON_from_data_auto (&rr.coin_pub),
+                                              "merchant_sig", 
GNUNET_JSON_from_data_auto (&msig),
+                                              "refund_amount", 
TALER_JSON_from_amount_nbo (&rr.refund_amount),
+                                              "refund_fee", 
TALER_JSON_from_amount_nbo (&rr.refund_fee))))
+        {
+          json_decref (refunds);
+          GNUNET_break (0);
+          resume_pay_with_error (pc,
+                                 MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                 TALER_EC_JSON_ALLOCATION_FAILURE,
+                                 "could not create JSON array");
+          return;
+        }
       }
 
       /* Resume and send back the response.  */
diff --git a/src/backend/taler-merchant-httpd_responses.c 
b/src/backend/taler-merchant-httpd_responses.c
index 19fa9fe..2b5832f 100644
--- a/src/backend/taler-merchant-httpd_responses.c
+++ b/src/backend/taler-merchant-httpd_responses.c
@@ -58,9 +58,10 @@ TMH_RESPONSE_make_json (const json_t *json)
     GNUNET_break (0);
     return NULL;
   }
-  (void) MHD_add_response_header (resp,
-                                  MHD_HTTP_HEADER_CONTENT_TYPE,
-                                  "application/json");
+  GNUNET_break (MHD_YES ==
+                MHD_add_response_header (resp,
+                                         MHD_HTTP_HEADER_CONTENT_TYPE,
+                                         "application/json"));
   return resp;
 }
 
@@ -331,9 +332,10 @@ void
 TMH_RESPONSE_add_global_headers (struct MHD_Response *response)
 {
   if (TMH_merchant_connection_close)
-    (void) MHD_add_response_header (response,
-                                    MHD_HTTP_HEADER_CONNECTION,
-                                    "close");
+    GNUNET_break (MHD_YES ==
+                  MHD_add_response_header (response,
+                                           MHD_HTTP_HEADER_CONNECTION,
+                                           "close"));
 }
 
 
diff --git a/src/backend/taler-merchant-httpd_tip-pickup.c 
b/src/backend/taler-merchant-httpd_tip-pickup.c
index d7e1919..90f9c89 100644
--- a/src/backend/taler-merchant-httpd_tip-pickup.c
+++ b/src/backend/taler-merchant-httpd_tip-pickup.c
@@ -227,6 +227,14 @@ run_pickup (struct MHD_Connection *connection,
                                   human);
   }
   sigs = json_array ();
+  if (NULL == sigs)
+  {
+    GNUNET_break (0);
+    return TMH_RESPONSE_reply_rc (connection,
+                                  MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                  TALER_EC_JSON_ALLOCATION_FAILURE,
+                                  "could not create JSON array");
+  }
   GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv.eddsa_priv,
                                       &reserve_pub.eddsa_pub);
   for (unsigned int i=0;i<pc->planchets_len;i++)
@@ -239,10 +247,19 @@ run_pickup (struct MHD_Connection *connection,
                   GNUNET_CRYPTO_eddsa_sign (&reserve_priv.eddsa_priv,
                                             &pd->wr.purpose,
                                             &reserve_sig.eddsa_signature));
-    json_array_append_new (sigs,
-                           json_pack ("{s:o}",
-                                      "reserve_sig",
-                                      GNUNET_JSON_from_data_auto 
(&reserve_sig)));
+    if (0 !=
+        json_array_append_new (sigs,
+                               json_pack ("{s:o}",
+                                          "reserve_sig",
+                                          GNUNET_JSON_from_data_auto 
(&reserve_sig))))
+    {
+      GNUNET_break (0);
+      json_decref (sigs);
+      return TMH_RESPONSE_reply_rc (connection,
+                                    MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                    TALER_EC_JSON_ALLOCATION_FAILURE,
+                                    "could not add element to JSON array");
+    }
   }
   return TMH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_OK,
diff --git a/src/backend/taler-merchant-httpd_trigger-pay.c 
b/src/backend/taler-merchant-httpd_trigger-pay.c
index 47c6815..7390750 100644
--- a/src/backend/taler-merchant-httpd_trigger-pay.c
+++ b/src/backend/taler-merchant-httpd_trigger-pay.c
@@ -52,8 +52,8 @@ add_header_from_arg (struct MHD_Connection *connection,
                                                  arg_name);
   if (NULL == arg)
     return;
-
-  MHD_add_response_header (response, header_name, arg);
+  GNUNET_break (MHD_YES ==
+                MHD_add_response_header (response, header_name, arg));
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]