descriptor: fix error code on OOM
What changed, and why it matters
This is a tiny one-line fix that changes the error code returned when memory allocation fails inside a Bitcoin descriptor policy-map validation function. Previously the code incorrectly reported a generic invalid-parameter error (WALLY_EINVAL) instead of an out-of-memory error (WALLY_ENOMEM). It does not fix a memory leak, crash, or code-execution bug; it only makes the reported error more accurate so callers can distinguish OOM from bad input.
Low priority: merge as a correctness improvement. Review callers of is_valid_policy_map/wally_descriptor_parse to confirm they handle WALLY_ENOMEM appropriately; no urgent security response required.
Security signals we found
Incorrect error code on allocation failure
Potential for callers to misclassify OOM as invalid input
No memory corruption, use-after-free, or overflow fixed
Evidence from the diff
In src/descriptor.c, is_valid_policy_map() builds a linked list of map entries. When wally_calloc() for a new list node returns NULL, the function previously set ret = WALLY_EINVAL. The patch changes that to WALLY_ENOMEM, which is the correct error code for allocation failure. The function still returns false and cleans up via the existing goto error path. No allocation behavior, size checks, or control flow change.
Changed components
src/descriptor.cis_valid_policy_map()Inspect captured patch +1 / −1
diff --git a/src/descriptor.c b/src/descriptor.c
index d569fb8..f141136 100644
--- a/src/descriptor.c
+++ b/src/descriptor.c
@@ -2906,7 +2906,7 @@ static bool is_valid_policy_map(const struct wally_map *map_in)
else if (!item->value || !item->value_len)
ret = WALLY_EINVAL; /* No key value */
else if (!(node = wally_calloc(sizeof(*node))))
- ret = WALLY_EINVAL;
+ ret = WALLY_ENOMEM;
else {
node->data = (const char*)item->value;
node->data_len = item->value_len;
Why this scored 18/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.