Skip to content

Commit

Permalink
Don't read one command past the end.
Browse files Browse the repository at this point in the history
Thanks to Evgeniy Stepanov for reporting this.

It might be a good idea to add a command iterator abstraction to MachO.h, but
this fixes the bug for now.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179848 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Apr 19, 2013
1 parent 4521019 commit db5f927
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/Object/MachOObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object,
macho::LCT_Segment64 : macho::LCT_Segment;

MachOObjectFile::LoadCommandInfo Load = getFirstLoadCommandInfo();
for (unsigned I = 0; I < LoadCommandCount; ++I) {
for (unsigned I = 0; ; ++I) {
if (Load.C.Type == macho::LCT_Symtab) {
assert(!SymtabLoadCmd && "Multiple symbol tables");
SymtabLoadCmd = Load.Ptr;
Expand All @@ -418,7 +418,11 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object,
Sections.push_back(reinterpret_cast<const char*>(Sec));
}
}
Load = getNextLoadCommandInfo(Load);

if (I == LoadCommandCount - 1)
break;
else
Load = getNextLoadCommandInfo(Load);
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/Object/ARM/objdump-thumb.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RUN: llvm-objdump -d -macho -triple=thumbv7-apple-ios \
RUN: %p/../Inputs/macho-text.thumb | FileCheck %s

CHECK: 0: 00 bf nop
Binary file added test/Object/Inputs/macho-text.thumb
Binary file not shown.
8 changes: 6 additions & 2 deletions tools/llvm-objdump/MachODump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ getSectionsAndSymbols(const macho::Header Header,

MachOObjectFile::LoadCommandInfo Command =
MachOObj->getFirstLoadCommandInfo();
for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
for (unsigned i = 0; ; ++i) {
if (Command.C.Type == macho::LCT_FunctionStarts) {
// We found a function starts segment, parse the addresses for later
// consumption.
Expand All @@ -214,7 +214,11 @@ getSectionsAndSymbols(const macho::Header Header,

MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
}
Command = MachOObj->getNextLoadCommandInfo(Command);

if (i == Header.NumLoadCommands - 1)
break;
else
Command = MachOObj->getNextLoadCommandInfo(Command);
}
}

Expand Down

0 comments on commit db5f927

Please sign in to comment.