Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 856a014

Browse files
committed
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268924 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ee20786 commit 856a014

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed
9.25 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
RUN: llvm-dsymutil -f -o - -oso-prepend-path=%p/.. %p/../Inputs/basic-with-libfat-test.macho.x86_64 | llvm-dwarfdump - | FileCheck %s
2+
3+
The test binary was created by force-linking the libfat-test.a fat archive
4+
with the basic linking test archive, like so:
5+
$ clang -all_load libfat-test.a libbasic.a basic1.macho.x86_64.o -Wl,-dead_strip -u _x86_64_var
6+
7+
CHECK: DW_AT_name{{.*}}"x86_64_var"
8+
CHECK: DW_AT_name{{.*}}"basic2.c"
9+
CHECK: DW_AT_name{{.*}}"basic3.c"
10+
CHECK: DW_AT_name{{.*}}"basic1.c"

tools/dsymutil/BinaryHolder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ BinaryHolder::GetMemoryBuffersForFile(StringRef Filename,
7979
}
8080

8181
CurrentFatBinary = std::move(*ErrOrFat);
82-
return getMachOFatMemoryBuffers(Filename, *CurrentMemoryBuffer,
82+
CurrentFatBinaryName = Filename;
83+
return getMachOFatMemoryBuffers(CurrentFatBinaryName, *CurrentMemoryBuffer,
8384
*CurrentFatBinary);
8485
}
8586

@@ -149,8 +150,9 @@ BinaryHolder::MapArchiveAndGetMemberBuffers(StringRef Filename,
149150
ArchiveBuffers.push_back(CurrentMemoryBuffer->getMemBufferRef());
150151
} else {
151152
CurrentFatBinary = std::move(*ErrOrFat);
153+
CurrentFatBinaryName = ArchiveFilename;
152154
ArchiveBuffers = getMachOFatMemoryBuffers(
153-
ArchiveFilename, *CurrentMemoryBuffer, *CurrentFatBinary);
155+
CurrentFatBinaryName, *CurrentMemoryBuffer, *CurrentFatBinary);
154156
}
155157

156158
for (auto MemRef : ArchiveBuffers) {

tools/dsymutil/BinaryHolder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class BinaryHolder {
4242
std::unique_ptr<MemoryBuffer> CurrentMemoryBuffer;
4343
std::vector<std::unique_ptr<object::ObjectFile>> CurrentObjectFiles;
4444
std::unique_ptr<object::MachOUniversalBinary> CurrentFatBinary;
45+
std::string CurrentFatBinaryName;
4546
bool Verbose;
4647

4748
/// Get the MemoryBufferRefs for the file specification in \p

0 commit comments

Comments
 (0)