From 5a1b02bc10547dbb8f0e5c0fccb7373fa55d0979 Mon Sep 17 00:00:00 2001 From: Derrick Lyndon Pallas Date: Mon, 22 Apr 2019 21:13:52 +0000 Subject: [PATCH] Fix uninitialized use of scatter_unit_uX due to padding These non-packed structures are placed into a std::vector. Later, they contents of the vector are memcpy'd and the CRC of this space is taken. Some compilers will zero the struct padding but GCC8.2 with -O2 at least will not. This means that the CRC is based on uninitialized memory. Since it is expected that these bytes will be memcpy'd, zero in place once they're in the std::vector. Found by Valgrind. Q.v. Issue #148 --- src/util/multibit_build.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/multibit_build.cpp b/src/util/multibit_build.cpp index ad6a0d6a..67bb9ec7 100644 --- a/src/util/multibit_build.cpp +++ b/src/util/multibit_build.cpp @@ -192,11 +192,11 @@ vector mmbBuildSparseIterator(const vector &bits, template static void add_scatter(vector *out, u32 offset, u64a mask) { - T su; + out->emplace_back(); + T &su = out->back(); memset(&su, 0, sizeof(su)); su.offset = offset; su.val = mask; - out->push_back(su); DEBUG_PRINTF("add %llu at offset %u\n", mask, offset); }