diff options
author | Zachary Turner <zturner@google.com> | 2017-06-03 00:33:35 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-06-03 00:33:35 +0000 |
commit | 5b74ff33e7a31c2939e978e1c5541883fb9cb25f (patch) | |
tree | e5757c6c0f7664a33e51bca87ca296578ec103bb /llvm/tools/llvm-pdbdump | |
parent | 4e8624d13825326a6e473d986197b5d9007b1153 (diff) | |
download | bcm5719-llvm-5b74ff33e7a31c2939e978e1c5541883fb9cb25f.tar.gz bcm5719-llvm-5b74ff33e7a31c2939e978e1c5541883fb9cb25f.zip |
[PDB] Fix use after free.
Previously MappedBlockStream owned its own BumpPtrAllocator that
it would allocate from when a read crossed a block boundary. This
way it could still return the user a contiguous buffer of the
requested size. However, It's not uncommon to open a stream, read
some stuff, close it, and then save the information for later.
After all, since the entire file is mapped into memory, the data
should always be available as long as the file is open.
Of course, the exception to this is when the data isn't *in* the
file, but rather in some buffer that we temporarily allocated to
present this contiguous view. And this buffer would get destroyed
as soon as the strema was closed.
The fix here is to force the user to specify the allocator, this
way it can provide an allocator that has whatever lifetime it
chooses.
Differential Revision: https://reviews.llvm.org/D33858
llvm-svn: 304623
Diffstat (limited to 'llvm/tools/llvm-pdbdump')
-rw-r--r-- | llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp | 3 | ||||
-rw-r--r-- | llvm/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp | 2 |
3 files changed, 6 insertions, 5 deletions
diff --git a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp index 7268d0b888d..31c342cd0f5 100644 --- a/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ b/llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -483,8 +483,8 @@ Error LLVMOutputStyle::dumpStreamBytes() { if (SI >= File.getNumStreams()) return make_error<RawError>(raw_error_code::no_stream); - auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(), - File.getMsfBuffer(), SI); + auto S = MappedBlockStream::createIndexedStream( + File.getMsfLayout(), File.getMsfBuffer(), SI, File.getAllocator()); if (!S) continue; DictScope DD(P, "Stream"); @@ -791,7 +791,7 @@ Error LLVMOutputStyle::dumpDbiStream() { if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) { auto ModStreamData = MappedBlockStream::createIndexedStream( File.getMsfLayout(), File.getMsfBuffer(), - Modi.getModuleStreamIndex()); + Modi.getModuleStreamIndex(), File.getAllocator()); ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData)); if (auto EC = ModS.reload()) diff --git a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp index 610b288c9ba..ee72b90b12d 100644 --- a/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp +++ b/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp @@ -229,7 +229,8 @@ Error YAMLOutputStyle::dumpDbiStream() { continue; auto ModStreamData = msf::MappedBlockStream::createIndexedStream( - File.getMsfLayout(), File.getMsfBuffer(), ModiStream); + File.getMsfLayout(), File.getMsfBuffer(), ModiStream, + File.getAllocator()); pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData)); if (auto EC = ModS.reload()) diff --git a/llvm/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp b/llvm/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp index 14cd222d138..5f09416a9ff 100644 --- a/llvm/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp +++ b/llvm/tools/llvm-pdbdump/fuzzer/llvm-pdbdump-fuzzer.cpp @@ -85,7 +85,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) { for (auto &Modi : DS.modules()) { auto ModStreamData = pdb::MappedBlockStream::createIndexedStream( - Modi.Info.getModuleStreamIndex(), *File); + Modi.Info.getModuleStreamIndex(), *File, File->getAllocator()); if (!ModStreamData) { consumeError(ModStreamData.takeError()); return 0; |