From 07527d9fbbecdc5bce1f3501cdd8037fa9246e0a Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Wed, 15 Mar 2023 13:26:23 -0500 Subject: [PATCH] fuzz: avoid buffer overflow in bech32 target If the fuzzer passes an empty data buffer, the fuzz target currently attempts to read from it. We should short-circuit instead. --- tests/fuzz/fuzz-bech32.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/fuzz/fuzz-bech32.c b/tests/fuzz/fuzz-bech32.c index 9acac0605ab3..41f6f57cf1e7 100644 --- a/tests/fuzz/fuzz-bech32.c +++ b/tests/fuzz/fuzz-bech32.c @@ -19,6 +19,9 @@ void run(const uint8_t *data, size_t size) int wit_version; bech32_encoding benc; + if (size < 1) + return; + /* Buffer size is defined in each function's doc comment. */ bech32_str = malloc(size + strlen(hrp_inv) + 8); benc = data[0] ? BECH32_ENCODING_BECH32 : BECH32_ENCODING_BECH32M;