From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 18 Nov 2026 17:41:26 +0100 Subject: [PATCH] merchant: bound the output index when replaying /pay token signatures A replay may account for fewer outputs than the signatures stored for the order, e.g. when it asks for fewer donation receipts, and the index then ran past the choice's outputs. Issue: https://bugs.taler.net/n/12207 Assisted by LLM --- ...-merchant-httpd_post-orders-ORDER_ID-pay.c | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 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..21fd9afc 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 @@ -4571,6 +4571,8 @@ append_output_token_sig (void *cls, struct GNUNET_CRYPTO_BlindedSignature *sig) { struct PayContext *pc = cls; + const struct TALER_MERCHANT_Contract *contract + = pc->check_contract.contract_terms; struct TALER_MERCHANT_ContractChoice *choice; const struct TALER_MERCHANT_ContractOutput *output; struct SignedOutputToken out; @@ -4581,11 +4583,6 @@ append_output_token_sig (void *cls, sizeof (out)); GNUNET_assert (TALER_MERCHANT_CONTRACT_VERSION_1 == pc->check_contract.contract_terms->pc->base->version); - choice = &pc->check_contract.contract_terms->pc->details.v1 - .choices[pc->parse_wallet_data.choice_index]; - output = &choice->outputs[pc->output_index_gen]; - cnt = count_output_tokens (pc, - output); out.output_index = pc->output_index_gen; out.h_issue.hash = *h_issue; out.sig.signature = sig; @@ -4593,6 +4590,22 @@ append_output_token_sig (void *cls, GNUNET_array_append (pc->output_tokens, pc->output_tokens_len, out); + if ( (pc->parse_wallet_data.choice_index < 0) || + (pc->parse_wallet_data.choice_index >= + contract->pc->details.v1.choices_len) ) + return; /* no choice to attribute outputs to */ + choice = &contract->pc->details.v1.choices[ + pc->parse_wallet_data.choice_index]; + if (pc->output_index_gen >= choice->outputs_len) + { + /* More signatures stored than this request's outputs account for, + e.g. because it asked for fewer donation receipts than paid. */ + GNUNET_break_op (0); + return; + } + output = &choice->outputs[pc->output_index_gen]; + cnt = count_output_tokens (pc, + output); /* Go to next output once we've output all tokens for the current one. */ pc->output_token_cnt++; if (pc->output_token_cnt >= cnt) -- 2.47.3