From 7dc075ae283f76669065c7357d6c8e4d39ae811e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 11 Jun 2016 13:54:11 +0200 Subject: check return values of json_array_append --- src/exchange-lib/exchange_api_refresh.c | 44 +++++++------ src/exchange/taler-exchange-httpd_keystate.c | 38 +++++++----- src/exchange/taler-exchange-httpd_responses.c | 89 +++++++++++++++------------ 3 files changed, 97 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c index 8331f5e78..e2e06a113 100644 --- a/src/exchange-lib/exchange_api_refresh.c +++ b/src/exchange-lib/exchange_api_refresh.c @@ -1317,8 +1317,9 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, GNUNET_CRYPTO_ecdhe_key_get_public (&mc->transfer_priv[j].ecdhe_priv, &transfer_pub.ecdhe_pub); - json_array_append (transfer_pubs, - GNUNET_JSON_from_data_auto (&transfer_pub)); + GNUNET_assert (0 == + json_array_append (transfer_pubs, + GNUNET_JSON_from_data_auto (&transfer_pub))); } /* now secret_encs */ @@ -1335,16 +1336,18 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, TALER_transfer_encrypt (&md->link_secrets[j], &trans_sec, &els)); - json_array_append (secret_encs, - GNUNET_JSON_from_data_auto (&els)); + GNUNET_assert (0 == + json_array_append (secret_encs, + GNUNET_JSON_from_data_auto (&els))); } /* now new_denoms */ for (i=0;inum_fresh_coins;i++) { - json_array_append (new_denoms, - GNUNET_JSON_from_rsa_public_key - (md->fresh_pks[i].rsa_public_key)); + GNUNET_assert (0 == + json_array_append (new_denoms, + GNUNET_JSON_from_rsa_public_key + (md->fresh_pks[i].rsa_public_key))); } /* now link_encs */ @@ -1362,11 +1365,13 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, TALER_refresh_encrypt (&rld, &md->link_secrets[j], &rle); - json_array_append (tmp, - GNUNET_JSON_from_data_auto (&rle)); + GNUNET_assert (0 == + json_array_append (tmp, + GNUNET_JSON_from_data_auto (&rle))); } - json_array_append (link_encs, - tmp); + GNUNET_assert (0 == + json_array_append (link_encs, + tmp)); } /* now coin_evs */ @@ -1404,13 +1409,15 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, json_decref (link_encs); return NULL; } - json_array_append (tmp, - GNUNET_JSON_from_data (coin_ev, - coin_ev_size)); + GNUNET_assert (0 == + json_array_append (tmp, + GNUNET_JSON_from_data (coin_ev, + coin_ev_size))); GNUNET_free (coin_ev); } - json_array_append (coin_evs, - tmp); + GNUNET_assert (0 == + json_array_append (coin_evs, + tmp)); } /* finally, assemble main JSON request from constitutent arrays */ @@ -1788,8 +1795,9 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange, noreval index! */ continue; } - json_array_append (transfer_privs, - GNUNET_JSON_from_data_auto (&md->melted_coin.transfer_priv[j])); + GNUNET_assert (0 == + json_array_append (transfer_privs, + GNUNET_JSON_from_data_auto (&md->melted_coin.transfer_priv[j]))); } /* build main JSON request */ diff --git a/src/exchange/taler-exchange-httpd_keystate.c b/src/exchange/taler-exchange-httpd_keystate.c index dc70fdba4..5366f9aaa 100644 --- a/src/exchange/taler-exchange-httpd_keystate.c +++ b/src/exchange/taler-exchange-httpd_keystate.c @@ -347,9 +347,10 @@ reload_keys_denom_iter (void *cls, } ctx->min_dk_expire = GNUNET_TIME_absolute_min (ctx->min_dk_expire, expire_deposit); - json_array_append_new (ctx->denom_keys_array, - denom_key_issue_to_json (&dki->denom_pub, - &dki->issue)); + GNUNET_assert (0 == + json_array_append_new (ctx->denom_keys_array, + denom_key_issue_to_json (&dki->denom_pub, + &dki->issue))); return GNUNET_OK; } @@ -436,8 +437,9 @@ reload_keys_sign_iter (void *cls, /* We use the most recent one, if it is valid now (not just in the near future) */ ctx->current_sign_key_issue = *ski; } - json_array_append_new (ctx->sign_keys_array, - sign_key_issue_to_json (&ski->issue)); + GNUNET_assert (0 == + json_array_append_new (ctx->sign_keys_array, + sign_key_issue_to_json (&ski->issue))); return GNUNET_OK; } @@ -465,12 +467,13 @@ auditor_to_json (const struct TALER_AuditorPublicKeyP *apub, ja = json_array (); for (i=0;idenom_hash), - "auditor_sig", - GNUNET_JSON_from_data_auto (asigs[i]))); + GNUNET_assert (0 == + json_array_append_new (ja, + json_pack ("{s:o, s:o}", + "denom_pub_h", + GNUNET_JSON_from_data_auto (&dki[i]->denom_hash), + "auditor_sig", + GNUNET_JSON_from_data_auto (asigs[i])))); return json_pack ("{s:o, s:s, s:o}", "denomination_keys", ja, @@ -536,12 +539,13 @@ reload_auditor_iter (void *cls, } } /* add auditor information to our /keys response */ - json_array_append_new (ctx->auditors_array, - auditor_to_json (apub, - auditor_url, - keep, - kept_asigs, - kept_dkis)); + GNUNET_assert (0 == + json_array_append_new (ctx->auditors_array, + auditor_to_json (apub, + auditor_url, + keep, + kept_asigs, + kept_dkis))); return GNUNET_OK; } diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c index 34aeec5da..1b3418dfb 100644 --- a/src/exchange/taler-exchange-httpd_responses.c +++ b/src/exchange/taler-exchange-httpd_responses.c @@ -526,12 +526,13 @@ compile_transaction_history (const struct TALER_EXCHANGEDB_TransactionList *tl) default: GNUNET_assert (0); } - json_array_append_new (history, - json_pack ("{s:s, s:o, s:o, s:o}", - "type", type, - "amount", TALER_JSON_from_amount (&value), - "signature", GNUNET_JSON_from_data_auto (sig), - "details", details)); + GNUNET_assert (0 == + json_array_append_new (history, + json_pack ("{s:s, s:o, s:o, s:o}", + "type", type, + "amount", TALER_JSON_from_amount (&value), + "signature", GNUNET_JSON_from_data_auto (sig), + "details", details))); } return history; } @@ -602,12 +603,13 @@ compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHistory *rh, return NULL; } ret = 1; - json_array_append_new (json_history, - json_pack ("{s:s, s:O, s:O, s:o}", - "type", "DEPOSIT", - "sender_account_details", pos->details.bank->sender_account_details, - "transfer_details", pos->details.bank->transfer_details, - "amount", TALER_JSON_from_amount (&pos->details.bank->amount))); + GNUNET_assert (0 == + json_array_append_new (json_history, + json_pack ("{s:s, s:O, s:O, s:o}", + "type", "DEPOSIT", + "sender_account_details", pos->details.bank->sender_account_details, + "transfer_details", pos->details.bank->transfer_details, + "amount", TALER_JSON_from_amount (&pos->details.bank->amount)))); break; case TALER_EXCHANGEDB_RO_WITHDRAW_COIN: break; @@ -649,12 +651,13 @@ compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHistory *rh, GNUNET_CRYPTO_rsa_public_key_hash (pos->details.withdraw->denom_pub.rsa_public_key, &wr.h_denomination_pub); wr.h_coin_envelope = pos->details.withdraw->h_coin_envelope; - json_array_append_new (json_history, - json_pack ("{s:s, s:o, s:o, s:o}", - "type", "WITHDRAW", - "signature", GNUNET_JSON_from_data_auto (&pos->details.withdraw->reserve_sig), - "details", GNUNET_JSON_from_data_auto (&wr), - "amount", TALER_JSON_from_amount (&value))); + GNUNET_assert (0 == + json_array_append_new (json_history, + json_pack ("{s:s, s:o, s:o, s:o}", + "type", "WITHDRAW", + "signature", GNUNET_JSON_from_data_auto (&pos->details.withdraw->reserve_sig), + "details", GNUNET_JSON_from_data_auto (&wr), + "amount", TALER_JSON_from_amount (&value)))); break; } } @@ -947,8 +950,9 @@ TMH_RESPONSE_reply_refresh_reveal_success (struct MHD_Connection *connection, json_object_set_new (obj, "ev_sig", GNUNET_JSON_from_rsa_signature (sigs[newcoin_index].rsa_signature)); - json_array_append_new (list, - obj); + GNUNET_assert (0 == + json_array_append_new (list, + obj)); } root = json_object (); json_object_set_new (root, @@ -1012,8 +1016,9 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, const struct TALER_DenominationPublicKey *pk; pk = &mc->denom_pubs[i]; - json_array_append_new (info_new, - GNUNET_JSON_from_rsa_public_key (pk->rsa_public_key)); + GNUNET_assert (0 == + json_array_append_new (info_new, + GNUNET_JSON_from_rsa_public_key (pk->rsa_public_key))); } info_commit = json_array (); @@ -1043,11 +1048,13 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, "blinding_key_enc", GNUNET_JSON_from_data_auto (&cc->refresh_link.blinding_key_enc)); - json_array_append_new (info_commit_k, - cc_json); + GNUNET_assert (0 == + json_array_append_new (info_commit_k, + cc_json)); } - json_array_append_new (info_commit, - info_commit_k); + GNUNET_assert (0 == + json_array_append_new (info_commit, + info_commit_k)); info_link_k = json_object (); cl = &mc->commit_links[k]; @@ -1057,8 +1064,9 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, json_object_set_new (info_link_k, "shared_secret_enc", GNUNET_JSON_from_data_auto (&cl->shared_secret_enc)); - json_array_append_new (info_links, - info_link_k); + GNUNET_assert (0 == + json_array_append_new (info_links, + info_link_k)); } return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_CONFLICT, @@ -1113,8 +1121,9 @@ TMH_RESPONSE_reply_refresh_link_success (struct MHD_Connection *connection, json_object_set_new (obj, "ev_sig", GNUNET_JSON_from_rsa_signature (pos->ev_sig.rsa_signature)); - json_array_append_new (list, - obj); + GNUNET_assert (0 == + json_array_append_new (list, + obj)); } root = json_object (); json_object_set_new (root, @@ -1126,8 +1135,9 @@ TMH_RESPONSE_reply_refresh_link_success (struct MHD_Connection *connection, json_object_set_new (root, "secret_enc", GNUNET_JSON_from_data_auto (&sessions[i].shared_secret_enc)); - json_array_append_new (mlist, - root); + GNUNET_assert (0 == + json_array_append_new (mlist, + root)); } res = TMH_RESPONSE_reply_json (connection, mlist, @@ -1267,13 +1277,14 @@ TMH_RESPONSE_reply_track_transfer_details (struct MHD_Connection *connection, GNUNET_CRYPTO_hash_context_read (hash_context, &dd, sizeof (struct TALER_WireDepositDetailP)); - json_array_append (deposits, - json_pack ("{s:o, s:I, s:o, s:o, s:o}", - "H_contract", GNUNET_JSON_from_data_auto (&wdd_pos->h_contract), - "transaction_id", (json_int_t) wdd_pos->transaction_id, - "coin_pub", GNUNET_JSON_from_data_auto (&wdd_pos->coin_pub), - "deposit_value", TALER_JSON_from_amount (&wdd_pos->deposit_value), - "deposit_fee", TALER_JSON_from_amount (&wdd_pos->deposit_fee))); + GNUNET_assert (0 == + json_array_append (deposits, + json_pack ("{s:o, s:I, s:o, s:o, s:o}", + "H_contract", GNUNET_JSON_from_data_auto (&wdd_pos->h_contract), + "transaction_id", (json_int_t) wdd_pos->transaction_id, + "coin_pub", GNUNET_JSON_from_data_auto (&wdd_pos->coin_pub), + "deposit_value", TALER_JSON_from_amount (&wdd_pos->deposit_value), + "deposit_fee", TALER_JSON_from_amount (&wdd_pos->deposit_fee)))); } wdp.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT); wdp.purpose.size = htonl (sizeof (struct TALER_WireDepositDataPS)); -- cgit v1.2.3