objdump fails to parse Mach-O binaries with n_desc bearing stabs
authorMichael Trent <mtrent@apple.com>
Sat, 23 Feb 2019 06:19:56 +0000 (06:19 +0000)
committerMichael Trent <mtrent@apple.com>
Sat, 23 Feb 2019 06:19:56 +0000 (06:19 +0000)
commit7dcfac617122976154ee39a8761147c5ff8ce1d9
tree5443aa682b070697977395855f5227c2c9740e40
parent6c664eda780454f18385f8d39cde4fab7773529e
objdump fails to parse Mach-O binaries with n_desc bearing stabs

Summary:
The objdump Mach-O parser uses MachOObjectFile::checkSymbolTable() to
verify the symbol table is in a legal state before dereferencing the
offsets in the table. This routine missed a test for N_STAB symbols
when validating the two-level name space library ordinal for undefined
symbols. If the binary in question contained a value in the n_desc high
byte that is larger than the list of loaded dylibs, checkSymbolTable()
will flag the library ordinal as being out of range. Most of the time
the n_desc field is set to 0 or to small values, but old final linked
binaries exist with N_STAB symbols bearing non-trivial n_desc fields.

The change here is simply to verify a symbol is not an N_STAB symbol
before consulting the values of n_other or n_desc.

rdar://44977336

Reviewers: lhames, pete, ab

Reviewed By: pete

Subscribers: llvm-commits, rupprecht

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58568

llvm-svn: 354722
llvm/lib/Object/MachOObjectFile.cpp
llvm/test/tools/llvm-objdump/X86/Inputs/macho-disassemble-stab-x86_64 [new file with mode: 0755]
llvm/test/tools/llvm-objdump/X86/macho-disassemble-stab.test [new file with mode: 0644]