Skip to content

Commit 0f12a7a

Browse files
committed
[llvm-nm] Fix heap-use-after-free while executing 'llvm-nm -n --export-symbols'
Use symbol's flags saved in NMSymbol::SymFlags inside NMSymbol::isDefined() since BasicSymbolRef::getFlags() requires the symbol's containing entity object to exist (which doesn't, causing llvm-nm to crash). Here is the AddressSanitizer report: ==3324663==ERROR: AddressSanitizer: heap-use-after-free on address 0x60e000000200 READ of size 8 at 0x60e000000200 thread T0 #0 0x55c6536785d8 in llvm::object::BasicSymbolRef::getFlags() const llvm-project/llvm/include/llvm/Object/SymbolicFile.h:207:24 #1 0x55c6536785d8 in (anonymous namespace)::NMSymbol::isDefined() const llvm-project/llvm/tools/llvm-nm/llvm-nm.cpp:241:37
1 parent 47daf14 commit 0f12a7a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

llvm/tools/llvm-nm/llvm-nm.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,8 @@ struct NMSymbol {
237237
std::string IndirectName;
238238

239239
bool isDefined() const {
240-
if (Sym.getRawDataRefImpl().p) {
241-
uint32_t Flags = cantFail(Sym.getFlags());
242-
return !(Flags & SymbolRef::SF_Undefined);
243-
}
240+
if (Sym.getRawDataRefImpl().p)
241+
return !(SymFlags & SymbolRef::SF_Undefined);
244242
return TypeChar != 'U';
245243
}
246244

0 commit comments

Comments
 (0)