From f10b779c838e213226980c131531edfe25bbe374 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 14 Jun 2017 11:11:17 +0200 Subject: [PATCH] pubkey: valgrind was reporting about unset memory in address parsing This is likely due to `libbase58` implicitly relying on the passed in buffer to be memset to 0, in order to report the correct decoded length. --- bitcoin/base58.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bitcoin/base58.c b/bitcoin/base58.c index d605117fd..a10b3f2be 100644 --- a/bitcoin/base58.c +++ b/bitcoin/base58.c @@ -53,12 +53,14 @@ static bool from_base58(u8 *version, const char *base58, size_t base58_len) { u8 buf[1 + sizeof(*rmd) + 4]; - + /* Avoid memcheck complaining if decoding resulted in a short value */ + memset(buf, 0, sizeof(buf)); b58_sha256_impl = my_sha256; size_t buflen = sizeof(buf); b58tobin(buf, &buflen, base58, base58_len); - int r = b58check(buf, sizeof(buf), base58, base58_len); + + int r = b58check(buf, buflen, base58, base58_len); *version = buf[0]; memcpy(rmd, buf + 1, sizeof(*rmd)); return r >= 0;