]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Fix uninitialized use of scatter_unit_uX due to padding
authorDerrick Lyndon Pallas <derrick@argosylabs.com>
Mon, 22 Apr 2019 21:13:52 +0000 (21:13 +0000)
committerChang, Harry <harry.chang@intel.com>
Tue, 13 Aug 2019 06:49:15 +0000 (14:49 +0800)
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

index ad6a0d6a69b541b5732b55a6a758392538bdebeb..67bb9ec7022ddeffd422c25c4fdc1da077736e3b 100644 (file)
@@ -192,11 +192,11 @@ vector<mmbit_sparse_iter> mmbBuildSparseIterator(const vector<u32> &bits,
 template<typename T>
 static
 void add_scatter(vector<T> *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);
 }