[llvm] r313193 - Fix a crash in llvm-nm for a bad Mach-O file that has an N_SECT type symbol and a zero n_sect value.
Kevin Enderby via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 14:01:49 PDT 2017
Author: enderby
Date: Wed Sep 13 14:01:49 2017
New Revision: 313193
URL: http://llvm.org/viewvc/llvm-project?rev=313193&view=rev
Log:
Fix a crash in llvm-nm for a bad Mach-O file that has an N_SECT type symbol and a zero n_sect value.
The code in llvm-nm for Mach-O files to determine the section type for an
N_SECT type symbol it will call getSymbolSection() and check for the error,
but in the case the n_sect value is zero it will return section_end() (aka nullptr).
And the code was using that and crashing instead of just returning a āsā for a
section or printing (?,?) as it would if getSymbolSection() returned an error.
rdar://33136604
Added:
llvm/trunk/test/tools/llvm-nm/X86/Inputs/macho-bad-zero-nsect-for-N_SECT (with props)
llvm/trunk/test/tools/llvm-nm/X86/macho-bad-zero-nsect-for-N_SECT.test
Modified:
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
Added: llvm/trunk/test/tools/llvm-nm/X86/Inputs/macho-bad-zero-nsect-for-N_SECT
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/Inputs/macho-bad-zero-nsect-for-N_SECT?rev=313193&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-nm/X86/Inputs/macho-bad-zero-nsect-for-N_SECT
------------------------------------------------------------------------------
svn:executable = *
Propchange: llvm/trunk/test/tools/llvm-nm/X86/Inputs/macho-bad-zero-nsect-for-N_SECT
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-nm/X86/macho-bad-zero-nsect-for-N_SECT.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/macho-bad-zero-nsect-for-N_SECT.test?rev=313193&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/X86/macho-bad-zero-nsect-for-N_SECT.test (added)
+++ llvm/trunk/test/tools/llvm-nm/X86/macho-bad-zero-nsect-for-N_SECT.test Wed Sep 13 14:01:49 2017
@@ -0,0 +1,8 @@
+RUN: llvm-nm %p/Inputs/macho-bad-zero-nsect-for-N_SECT | FileCheck -check-prefix DEFAULT %s
+DEFAULT: 0000000000000000 S dyld_stub_binder
+
+RUN: llvm-nm -m %p/Inputs/macho-bad-zero-nsect-for-N_SECT | FileCheck -check-prefix MACHO %s
+MACHO: 0000000000000000 (?,?) private external dyld_stub_binder
+
+RUN: llvm-nm -x %p/Inputs/macho-bad-zero-nsect-for-N_SECT | FileCheck -check-prefix HEX %s
+HEX: 0000000000000000 1f 00 0000 00000024 dyld_stub_binder
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=313193&r1=313192&r2=313193&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Sep 13 14:01:49 2017
@@ -486,6 +486,10 @@ static void darwinPrintSymbol(SymbolicFi
break;
}
Sec = *SecOrErr;
+ if (Sec == MachO->section_end()) {
+ outs() << "(?,?) ";
+ break;
+ }
} else {
Sec = I->Section;
}
@@ -997,6 +1001,8 @@ static char getSymbolNMTypeChar(MachOObj
return 's';
}
section_iterator Sec = *SecOrErr;
+ if (Sec == Obj.section_end())
+ return 's';
DataRefImpl Ref = Sec->getRawDataRefImpl();
StringRef SectionName;
Obj.getSectionName(Ref, SectionName);
More information about the llvm-commits
mailing list