Fix use after free in BinaryStream library.
authorZachary Turner <zturner@google.com>
Wed, 3 May 2017 05:34:00 +0000 (05:34 +0000)
committerZachary Turner <zturner@google.com>
Wed, 3 May 2017 05:34:00 +0000 (05:34 +0000)
commit59e83892e0a029a5d773c8d0a835d471df3ccfd2
treeab5a7c8453b62a42f2188ded142d3c0e20342fc6
parent79d310713a618b5ba8d2a3ae9cbf58f2dae6899a
Fix use after free in BinaryStream library.

This was reported by the ASAN bot, and it turned out to be
a fairly fundamental problem with the design of VarStreamArray
and the way it passes context information to the extractor.

The fix was cumbersome, and I'm not entirely pleased with it,
so I plan to revisit this design in the future when I'm not
pressed to get the bots green again.  For now, this fixes
the issue by storing the context information by value instead
of by reference, and introduces some impossibly-confusing
template magic to make things "work".

llvm-svn: 301999
12 files changed:
llvm/include/llvm/DebugInfo/CodeView/CVRecord.h
llvm/include/llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h
llvm/include/llvm/DebugInfo/CodeView/ModuleDebugFragmentRecord.h
llvm/include/llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h
llvm/include/llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h
llvm/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h
llvm/include/llvm/Support/BinaryStreamArray.h
llvm/include/llvm/Support/BinaryStreamReader.h
llvm/lib/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.cpp
llvm/lib/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.cpp
llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp
llvm/unittests/Support/BinaryStreamTest.cpp