View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012195 | Taler | merchant backend | public | 2026-11-18 15:01 | 2026-11-18 15:02 |
| Reporter | bot-cg [agent] | ||||
| Priority | normal | Severity | minor | ||
| Status | new | ||||
| Summary | 0012195: TALER_MERCHANTDB_insert_transfer_details puts four stack arrays sized by the exchange's deposit count | ||||
| Description | insert_transfer_details.c declares coin_values, deposit_fees, coin_pubs and contract_terms as variable-length arrays of td->details_length entries, 64 bytes per deposit. details_length is json_array_size() of the deposits in the exchange's GET /transfers/$WTID reply (exchange_api_get-transfers-WTID.c), with no limit other than the 40 MiB download and allocation caps. From about 131000 deposits in one wire transfer the arrays exceed the default 8 MiB stack and taler-merchant-reconciliation crashes, then crashes again on the same transfer after every restart. Such a transfer can come from a malicious exchange, but also from an honest one aggregating a very busy merchant's deposits. The attached patch allocates the four arrays on the heap and frees them on every return path. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 12195-merchantdb-keep-transfer-deposit-arrays-off-the-stac.patch (3,557 bytes)
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 16:01:54 +0100
Subject: [PATCH] merchantdb: keep transfer deposit arrays off the stack
The number of deposits in a wire transfer is set by the exchange, and a
large transfer overflowed the stack of taler-merchant-reconciliation.
Issue: https://bugs.taler.net/n/12195
Assisted by LLM
---
src/backenddb/insert_transfer_details.c | 34 +++++++++++++++++++------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/src/backenddb/insert_transfer_details.c b/src/backenddb/insert_transfer_details.c
index 3cfef662..446762c8 100644
--- a/src/backenddb/insert_transfer_details.c
+++ b/src/backenddb/insert_transfer_details.c
@@ -43,10 +43,11 @@ TALER_MERCHANTDB_insert_transfer_details (
unsigned int *num_settled_orders)
{
unsigned int len = td->details_length;
- struct TALER_Amount coin_values[GNUNET_NZL (len)];
- struct TALER_Amount deposit_fees[GNUNET_NZL (len)];
- const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (len)];
- const struct TALER_PrivateContractHashP *contract_terms[GNUNET_NZL (len)];
+ /* on the heap: the exchange decides how many deposits a transfer has */
+ struct TALER_Amount *coin_values;
+ struct TALER_Amount *deposit_fees;
+ const struct TALER_CoinSpendPublicKeyP **coin_pubs;
+ const struct TALER_PrivateContractHashP **contract_terms;
enum GNUNET_DB_QueryStatus qs;
bool duplicate = false;
@@ -65,6 +66,14 @@ TALER_MERCHANTDB_insert_transfer_details (
exchange_url);
}
+ coin_values = GNUNET_new_array (GNUNET_NZL (len),
+ struct TALER_Amount);
+ deposit_fees = GNUNET_new_array (GNUNET_NZL (len),
+ struct TALER_Amount);
+ coin_pubs = GNUNET_new_array (GNUNET_NZL (len),
+ const struct TALER_CoinSpendPublicKeyP *);
+ contract_terms = GNUNET_new_array (GNUNET_NZL (len),
+ const struct TALER_PrivateContractHashP *);
for (unsigned int i = 0; i<len; i++)
{
const struct TALER_TrackTransferDetails *tdd = &td->details[i];
@@ -86,7 +95,8 @@ TALER_MERCHANTDB_insert_transfer_details (
"insert transfer details"))
{
GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ goto cleanup;
}
{
@@ -166,7 +176,7 @@ TALER_MERCHANTDB_insert_transfer_details (
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"'insert_transfer_details' failed with status %d\n",
qs);
- return qs;
+ goto cleanup;
}
{
/* One aggregated transfer can settle many orders; notify
@@ -210,12 +220,20 @@ TALER_MERCHANTDB_insert_transfer_details (
"Committing transaction...\n");
qs = TALER_MERCHANTDB_commit (pg);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ {
+ qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ goto cleanup;
+ }
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
break;
}
if (duplicate)
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+cleanup:
+ GNUNET_free (coin_values);
+ GNUNET_free (deposit_fees);
+ GNUNET_free (coin_pubs);
+ GNUNET_free (contract_terms);
return qs;
}
--
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 15:01 | bot-cg | New Issue | |
| 2026-11-18 15:01 | bot-cg | Relationship added | child of 0012186 |
| 2026-11-18 15:01 | bot-cg | Implementer | => Bohdan |
| 2026-11-18 15:01 | bot-cg | Reviewer | => sebasjm |
| 2026-11-18 15:01 | bot-cg | Release signed by | => Florian Dold |
| 2026-11-18 15:01 | bot-cg | Deployed by | => Bohdan |
| 2026-11-18 15:01 | bot-cg | Verifier | => sebasjm |
| 2026-11-18 15:01 | bot-cg | Communicator | => CM_7 |
| 2026-11-18 15:02 | bot-cg | File Added: 12195-merchantdb-keep-transfer-deposit-arrays-off-the-stac.patch |