From 59e83892e0a029a5d773c8d0a835d471df3ccfd2 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Wed, 3 May 2017 05:34:00 +0000 Subject: 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 --- llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp') diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp index f994b4538ef..867864e47dc 100644 --- a/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp @@ -89,6 +89,14 @@ uint32_t DbiModuleDescriptorBuilder::calculateSerializedLength() const { return alignTo(L + M + O, sizeof(uint32_t)); } +template struct Foo { + explicit Foo(T &&Answer) : Answer(Answer) {} + + T Answer; +}; + +template Foo makeFoo(T &&t) { return Foo(std::move(t)); } + void DbiModuleDescriptorBuilder::finalize() { Layout.FileNameOffs = 0; // TODO: Fix this Layout.Flags = 0; // TODO: Fix this -- cgit v1.2.3