From c05d7e4f7859993a225765bcb57b6e3cf762ab7a Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Fri, 7 Apr 2023 12:57:10 -0500 Subject: [PATCH] bitcoin: avoid adding to NULL Detected by UBSan: $ UBSAN_OPTIONS=print_stacktrace=1 ./wallet/test/run-psbt_fixup bitcoin/psbt.c:733:2: runtime error: applying zero offset to null pointer #0 0x53c829 in psbt_from_bytes lightning/bitcoin/psbt.c:733:2 #1 0x5adcb0 in main lightning/wallet/test/run-psbt_fixup.c:174:10 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior bitcoin/psbt.c:733:2 --- common/utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/utils.h b/common/utils.h index 6937a2e8b9a6..abf3ca6848e0 100644 --- a/common/utils.h +++ b/common/utils.h @@ -123,10 +123,10 @@ void tal_wally_end(const tal_t *parent); /* ... or this if you want to reparent onto something which is * allocated by libwally here. Fixes up this from_wally obj to have a * proper tal_name, too! */ -#define tal_wally_end_onto(parent, from_wally, type) \ - tal_wally_end_onto_((parent), \ - (from_wally) + 0*sizeof((from_wally) == (type *)0), \ - stringify(type)) +#define tal_wally_end_onto(parent, from_wally, type) \ + tal_wally_end_onto_( \ + (parent), (from_wally), \ + &stringify(type)[0 * sizeof((from_wally) == (type *)0)]) void tal_wally_end_onto_(const tal_t *parent, tal_t *from_wally, const char *from_wally_name);