tx: fix output clearing size on tx_input_init_alloc failure
What changed, and why it matters
This commit fixes a small but real bug in a Bitcoin/Elements transaction library. When creating a new transaction input fails, the code was trying to securely wipe memory using the wrong size: it used the size of a transaction output instead of the size of a transaction input. On most systems this means the clearing is ineffective or incomplete, so secret data (like scripts or witness data) could remain in memory longer than intended. It is a memory-clearing bug, not a direct remote exploit, but it weakens a security safeguard.
Apply the patch. After applying, audit other clear_and_free() and clear() calls in transaction.c for matching object types and sizes, and consider adding static analysis or unit tests that verify clearing sizes match allocation sizes.
Security signals we found
Incorrect secure memory wipe size in failure path
Potential sensitive data retention (scripts/witness data) in heap
Type/size mismatch between allocated object and clearing operation
Reported by external researcher
Evidence from the diff
In wally_tx_input_init_alloc(), the failure path calls clear_and_free(*output, sizeof(struct wally_tx_output)) on a struct wally_tx_input pointer. The patch changes the cleared size to sizeof(struct wally_tx_input). Because the two structures are not guaranteed to be the same size, the original code either under-clears or mis-clears the allocation. This is a sensitive-data-retention / secure-clearing bug in an error-handling path. The reporter is credited, but no CVE or vendor security advisory is present in the supplied materials.
Changed components
src/transaction.cwally_tx_input_init_alloc()Inspect captured patch +1 / −1
diff --git a/src/transaction.c b/src/transaction.c
index 17f7277..0b3f13f 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -742,7 +742,7 @@ int wally_tx_input_init_alloc(const unsigned char *txhash, size_t txhash_len,
script, script_len, witness, *output);
if (ret != WALLY_OK) {
- clear_and_free(*output, sizeof(struct wally_tx_output));
+ clear_and_free(*output, sizeof(struct wally_tx_input));
*output = NULL;
}
return ret;
Why this scored 44/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.