tx: add missing check for NULL written param
What changed, and why it matters
This commit fixes a simple but real bug in a transaction helper function. Before the fix, if a caller accidentally passed a null pointer as the output parameter, the library would crash by writing to address zero. The fix adds a standard null check and returns an error instead. It is a defensive hardening change rather than an active remote exploit, but it removes a reliable local crash path.
Apply the patch. It is low-risk and aligns the function with the rest of the API's null-check conventions. Review other similar one-liner output functions for the same pattern.
Security signals we found
NULL pointer dereference crash fixed
Missing input validation on public API output parameter
Reported by external researcher with a proof-of-concept tool
Small, targeted hardening patch
Evidence from the diff
wally_tx_vsize_from_weight() in src/transaction.c now validates that the ‘written’ output pointer is non-NULL before dereferencing it. Previously the function immediately executed ‘*written = (weight + 3) / 4;’, causing a NULL-pointer dereference when callers passed NULL. The patch adds an early return of WALLY_EINVAL if !written, consistent with other wally functions.
Changed components
src/transaction.cwally_tx_vsize_from_weight()libwally-core transaction utility APIInspect captured patch +2 / −0
diff --git a/src/transaction.c b/src/transaction.c
index ad3c422..17f7277 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -1857,6 +1857,8 @@ int wally_tx_get_weight(const struct wally_tx *tx, size_t *written)
int wally_tx_vsize_from_weight(size_t weight, size_t *written)
{
+ if (!written)
+ return WALLY_EINVAL;
*written = (weight + 3) / 4; /* ceil(weight/4) */
return WALLY_OK;
}
Why this scored 36/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.