From 77946bd9fe70754c67bc762dd34efd95cc2a6736 Mon Sep 17 00:00:00 2001 From: niftynei Date: Fri, 26 Jun 2020 16:08:38 -0500 Subject: [PATCH] fromwire: return NULL if array empty libwally's API requires us to pass in NULL pointers if the array size is zero, so we update our array from wire-er to comply with this requirement [ Added fix to avoid tal_resize() of NULL -- RR ] --- common/features.c | 5 +++-- wire/fromwire.c | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/features.c b/common/features.c index 375196e5d..ff193c203 100644 --- a/common/features.c +++ b/common/features.c @@ -195,8 +195,9 @@ u8 *get_agreed_channelfeatures(const tal_t *ctx, max_len = (i / 8) + 1; } - /* Trim to length */ - tal_resize(&f, max_len); + /* Trim to length (unless it's already NULL). */ + if (f) + tal_resize(&f, max_len); return f; } diff --git a/wire/fromwire.c b/wire/fromwire.c index 4009c7f7e..6045b7f98 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -211,6 +211,9 @@ u8 *fromwire_tal_arrn(const tal_t *ctx, const u8 **cursor, size_t *max, size_t num) { u8 *arr; + if (num == 0) + return NULL; + if (num > *max) return fromwire_fail(cursor, max);