From ccac3a02298a02bc359f9ea0ee03c9a8d54c68ab Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Tue, 25 Nov 2014 15:24:07 +0000 Subject: [PATCH] [msan] Annotate zlib functions for MemorySanitizer. Mark destination buffer in zlib::compress and zlib::decompress as fully initialized. When building LLVM with system zlib and MemorySanitizer instrumentation, MSan does not observe memory writes in zlib code and erroneously considers zlib output buffers as uninitialized, resulting in false use-of-uninitialized memory reports. This change helps MSan understand the state of that memory and prevents such reports. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222763 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Compression.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Support/Compression.cpp b/lib/Support/Compression.cpp index c32eb21343e..17ae2957d12 100644 --- a/lib/Support/Compression.cpp +++ b/lib/Support/Compression.cpp @@ -54,6 +54,9 @@ zlib::Status zlib::compress(StringRef InputBuffer, Status Res = encodeZlibReturnValue(::compress2( (Bytef *)CompressedBuffer.data(), &CompressedSize, (const Bytef *)InputBuffer.data(), InputBuffer.size(), CLevel)); + // Tell MemorySanitizer that zlib output buffer is fully initialized. + // This avoids a false report when running LLVM with uninstrumented ZLib. + __msan_unpoison(CompressedBuffer.data(), CompressedSize); CompressedBuffer.resize(CompressedSize); return Res; } @@ -65,6 +68,9 @@ zlib::Status zlib::uncompress(StringRef InputBuffer, Status Res = encodeZlibReturnValue(::uncompress( (Bytef *)UncompressedBuffer.data(), (uLongf *)&UncompressedSize, (const Bytef *)InputBuffer.data(), InputBuffer.size())); + // Tell MemorySanitizer that zlib output buffer is fully initialized. + // This avoids a false report when running LLVM with uninstrumented ZLib. + __msan_unpoison(UncompressedBuffer.data(), UncompressedSize); UncompressedBuffer.resize(UncompressedSize); return Res; } -- 2.40.0