summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-04 00:07:57 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-04 00:07:57 +0200
commit3b9eff33d011b1042934f5b57a1baf3f759909f8 (patch)
tree5f8152069d010cec0e190ea56c68c16b25c78eb7
parentb4e8a39878078e5e51c770380bdbe5d636e066b4 (diff)
downloadmerchant-3b9eff33d011b1042934f5b57a1baf3f759909f8.tar.gz
merchant-3b9eff33d011b1042934f5b57a1baf3f759909f8.tar.bz2
merchant-3b9eff33d011b1042934f5b57a1baf3f759909f8.zip
handle json allocation failures, check MHD response code and log at least
-rw-r--r--src/backend/taler-merchant-httpd_pay.c33
-rw-r--r--src/backend/taler-merchant-httpd_responses.c14
-rw-r--r--src/backend/taler-merchant-httpd_tip-pickup.c25
-rw-r--r--src/backend/taler-merchant-httpd_trigger-pay.c4
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 f87d1c82..2764a0c5 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 19fa9fe2..2b5832f6 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 d7e19196..90f9c891 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 47c68157..73907500 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));
}