From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 18 Nov 2026 16:01:54 +0100 Subject: [PATCH] merchant: do not set /pay array counts before their arrays exist pay_context_cleanup() walks coins, tokens and token envelopes by their counts, so a count must not be set when the length check refuses the array, and null token envelopes have no blinded message to release. Issue: https://bugs.taler.net/n/12193 Assisted by LLM --- ...-merchant-httpd_post-orders-ORDER_ID-pay.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c index 38c2854a..c1d2bf79 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c @@ -5101,9 +5101,7 @@ phase_parse_wallet_data (struct PayContext *pc) } } - pc->parse_wallet_data.token_envelopes_cnt - = json_array_size (tokens_evs); - if (pc->parse_wallet_data.token_envelopes_cnt > + if (json_array_size (tokens_evs) > MAX_TOKEN_ALLOWED_OUTPUTS) { GNUNET_break_op (0); @@ -5115,6 +5113,8 @@ phase_parse_wallet_data (struct PayContext *pc) "'tokens_evs' array too long")); return; } + pc->parse_wallet_data.token_envelopes_cnt + = json_array_size (tokens_evs); pc->parse_wallet_data.token_envelopes = GNUNET_new_array (pc->parse_wallet_data.token_envelopes_cnt, struct TokenEnvelope); @@ -5388,8 +5388,7 @@ phase_parse_pay (struct PayContext *pc) pc->parse_pay.session_id = GNUNET_strdup (""); } - pc->parse_pay.coins_cnt = json_array_size (coins); - if (pc->parse_pay.coins_cnt > MAX_COIN_ALLOWED_COINS) + if (json_array_size (coins) > MAX_COIN_ALLOWED_COINS) { GNUNET_break_op (0); pay_end (pc, @@ -5401,6 +5400,7 @@ phase_parse_pay (struct PayContext *pc) return; } /* note: 1 coin = 1 deposit confirmation expected */ + pc->parse_pay.coins_cnt = json_array_size (coins); pc->parse_pay.dc = GNUNET_new_array (pc->parse_pay.coins_cnt, struct DepositConfirmation); @@ -5535,8 +5535,7 @@ phase_parse_pay (struct PayContext *pc) } } - pc->parse_pay.tokens_cnt = json_array_size (tokens); - if (pc->parse_pay.tokens_cnt > MAX_TOKEN_ALLOWED_INPUTS) + if (json_array_size (tokens) > MAX_TOKEN_ALLOWED_INPUTS) { GNUNET_break_op (0); pay_end (pc, @@ -5548,6 +5547,7 @@ phase_parse_pay (struct PayContext *pc) return; } + pc->parse_pay.tokens_cnt = json_array_size (tokens); pc->parse_pay.tokens = GNUNET_new_array (pc->parse_pay.tokens_cnt, struct TokenUseConfirmation); @@ -5693,7 +5693,10 @@ pay_context_cleanup (void *cls) struct TokenEnvelope *ev = &pc->parse_wallet_data.token_envelopes[i]; - GNUNET_CRYPTO_blinded_message_decref (ev->blinded_token.blinded_pub); + /* null entries in tokens_evs, and those after a parse error, + have no blinded message */ + if (NULL != ev->blinded_token.blinded_pub) + GNUNET_CRYPTO_blinded_message_decref (ev->blinded_token.blinded_pub); } GNUNET_free (pc->parse_wallet_data.token_envelopes); if (NULL != pc->output_tokens) -- 2.47.3