diff options
| author | Frederic Riss <friss@apple.com> | 2016-05-09 14:44:14 +0000 |
|---|---|---|
| committer | Frederic Riss <friss@apple.com> | 2016-05-09 14:44:14 +0000 |
| commit | 98f489ce82f250b31a50b0f1475783642e4ad557 (patch) | |
| tree | 4b672aaff4f60bd491804a300c065b5513625881 /llvm/tools | |
| parent | 1dfd5b16942febb535b7cf20f1c0a77b86e2adf3 (diff) | |
| download | bcm5719-llvm-98f489ce82f250b31a50b0f1475783642e4ad557.tar.gz bcm5719-llvm-98f489ce82f250b31a50b0f1475783642e4ad557.zip | |
[dsymutil] Prevent use-after-free
The BinaryHolder would query the archive member MemoryBuffer name
to check if the current open archive also contains the next requested
objectfile. This comparison was using a StringRef to a temporary
buffer. It only happened with fat archives. This commit adds long-lived
storage along with the MemoryBuffers for the fat archive filename.
The added test would fail during an ASAN build without the fix.
llvm-svn: 268924
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/dsymutil/BinaryHolder.cpp | 6 | ||||
| -rw-r--r-- | llvm/tools/dsymutil/BinaryHolder.h | 1 |
2 files changed, 5 insertions, 2 deletions
diff --git a/llvm/tools/dsymutil/BinaryHolder.cpp b/llvm/tools/dsymutil/BinaryHolder.cpp index 7644f01952f..32d176645bf 100644 --- a/llvm/tools/dsymutil/BinaryHolder.cpp +++ b/llvm/tools/dsymutil/BinaryHolder.cpp @@ -79,7 +79,8 @@ BinaryHolder::GetMemoryBuffersForFile(StringRef Filename, } CurrentFatBinary = std::move(*ErrOrFat); - return getMachOFatMemoryBuffers(Filename, *CurrentMemoryBuffer, + CurrentFatBinaryName = Filename; + return getMachOFatMemoryBuffers(CurrentFatBinaryName, *CurrentMemoryBuffer, *CurrentFatBinary); } @@ -149,8 +150,9 @@ BinaryHolder::MapArchiveAndGetMemberBuffers(StringRef Filename, ArchiveBuffers.push_back(CurrentMemoryBuffer->getMemBufferRef()); } else { CurrentFatBinary = std::move(*ErrOrFat); + CurrentFatBinaryName = ArchiveFilename; ArchiveBuffers = getMachOFatMemoryBuffers( - ArchiveFilename, *CurrentMemoryBuffer, *CurrentFatBinary); + CurrentFatBinaryName, *CurrentMemoryBuffer, *CurrentFatBinary); } for (auto MemRef : ArchiveBuffers) { diff --git a/llvm/tools/dsymutil/BinaryHolder.h b/llvm/tools/dsymutil/BinaryHolder.h index d56a39597c2..97508b9fb09 100644 --- a/llvm/tools/dsymutil/BinaryHolder.h +++ b/llvm/tools/dsymutil/BinaryHolder.h @@ -42,6 +42,7 @@ class BinaryHolder { std::unique_ptr<MemoryBuffer> CurrentMemoryBuffer; std::vector<std::unique_ptr<object::ObjectFile>> CurrentObjectFiles; std::unique_ptr<object::MachOUniversalBinary> CurrentFatBinary; + std::string CurrentFatBinaryName; bool Verbose; /// Get the MemoryBufferRefs for the file specification in \p |

