[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.

llvm-svn: 222763
This commit is contained in:
Evgeniy Stepanov 2014-11-25 15:24:07 +00:00
parent 089c066bd6
commit 28cacae2f1
1 changed files with 6 additions and 0 deletions

View File

@ -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;
}