View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012207 | Taler | merchant backend | public | 2026-11-18 16:41 | 2026-11-18 16:48 |
| Reporter | bot-cg [agent] | Locked by | Christian Grothoff | ||
| Estimated effort (hours) | 0.5 | ||||
| Priority | normal | Severity | crash | ||
| Status | planning | ||||
| Product Version | git (master) | ||||
| Target Version | 1.7 | ||||
| Summary | 0012207: POST /orders/$ID/pay replay with fewer donation key pairs reads past choice->outputs | ||||
| Description | On an idempotent replay of a paid order, phase_contract_paid() (taler-merchant-httpd_post-orders-ORDER_ID-pay.c) runs TALER_MERCHANTDB_iterate_order_token_blinded_sigs() with append_output_token_sig() as callback. That function walks the stored signatures and attributes each to choice->outputs[pc->output_index_gen], advancing output_index_gen with count_output_tokens(), which counts donation receipts with the replay request's num_bkps. The stored signatures were counted with the original request's num_bkps. When the replay has fewer (for instance no "donau" object at all, after an original payment that received two or more receipts), the surplus signatures advance output_index_gen to outputs_len, choice->outputs[outputs_len] is read past the end of the array, and count_output_tokens() asserts on the garbage output type. Nothing bounds output_index_gen, and choice_index is not re-checked on this path either. Confirmed by reading the code at 495a791d; not reproduced at runtime. The attached patch stops attributing signatures once output_index_gen reaches outputs_len, and checks choice_index before indexing the choices. | ||||
| Additional Information | Recorded as R2-M4 in the merchant review notes; the patch is that review's 2105 unchanged, rebased onto 495a791d. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 12207-merchant-bound-the-output-index-when-replaying-pay-t.patch (2,854 bytes)
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
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
| ||||
| child of | 0012186 | new | Unchecked array lengths and counts in exchange, merchant and anastasis: review after 2a57cbcaf [meta] |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-18 16:41 | bot-cg | New Issue | |
| 2026-11-18 16:41 | bot-cg | Relationship added | child of 0012186 |
| 2026-11-18 16:41 | bot-cg | Implementer | => Bohdan |
| 2026-11-18 16:41 | bot-cg | Reviewer | => sebasjm |
| 2026-11-18 16:41 | bot-cg | Release signed by | => Florian Dold |
| 2026-11-18 16:41 | bot-cg | Deployed by | => Bohdan |
| 2026-11-18 16:41 | bot-cg | Verifier | => sebasjm |
| 2026-11-18 16:41 | bot-cg | Communicator | => CM_7 |
| 2026-11-18 16:41 | bot-cg | File Added: 12207-merchant-bound-the-output-index-when-replaying-pay-t.patch | |
| 2026-11-18 16:47 | Christian Grothoff | Locked by | => Christian Grothoff |
| 2026-11-18 16:47 | Christian Grothoff | Status | new => planning |
| 2026-11-18 16:48 | Christian Grothoff | Implementer | Bohdan => Christian Grothoff |
| 2026-11-18 16:48 | Christian Grothoff | Reviewer | sebasjm => Florian Dold |
| 2026-11-18 16:48 | Christian Grothoff | Release signed by | Florian Dold => Christian Grothoff |
| 2026-11-18 16:48 | Christian Grothoff | Deployed by | Bohdan => vecirex |
| 2026-11-18 16:48 | Christian Grothoff | Verifier | sebasjm => vecirex |
| 2026-11-18 16:48 | Christian Grothoff | Target Version | => 1.7 |
| 2026-11-18 16:48 | Christian Grothoff | Estimated effort (hours) | => 0.5 |