forked from OSchip/llvm-project
Don't read one command past the end.
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. llvm-svn: 179848
This commit is contained in:
parent
a155ab2dd2
commit
feef8c2469
|
@ -405,7 +405,7 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object,
|
||||||
macho::LCT_Segment64 : macho::LCT_Segment;
|
macho::LCT_Segment64 : macho::LCT_Segment;
|
||||||
|
|
||||||
MachOObjectFile::LoadCommandInfo Load = getFirstLoadCommandInfo();
|
MachOObjectFile::LoadCommandInfo Load = getFirstLoadCommandInfo();
|
||||||
for (unsigned I = 0; I < LoadCommandCount; ++I) {
|
for (unsigned I = 0; ; ++I) {
|
||||||
if (Load.C.Type == macho::LCT_Symtab) {
|
if (Load.C.Type == macho::LCT_Symtab) {
|
||||||
assert(!SymtabLoadCmd && "Multiple symbol tables");
|
assert(!SymtabLoadCmd && "Multiple symbol tables");
|
||||||
SymtabLoadCmd = Load.Ptr;
|
SymtabLoadCmd = Load.Ptr;
|
||||||
|
@ -418,7 +418,11 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object,
|
||||||
Sections.push_back(reinterpret_cast<const char*>(Sec));
|
Sections.push_back(reinterpret_cast<const char*>(Sec));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Load = getNextLoadCommandInfo(Load);
|
|
||||||
|
if (I == LoadCommandCount - 1)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
Load = getNextLoadCommandInfo(Load);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 not shown.
|
@ -205,7 +205,7 @@ getSectionsAndSymbols(const macho::Header Header,
|
||||||
|
|
||||||
MachOObjectFile::LoadCommandInfo Command =
|
MachOObjectFile::LoadCommandInfo Command =
|
||||||
MachOObj->getFirstLoadCommandInfo();
|
MachOObj->getFirstLoadCommandInfo();
|
||||||
for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
|
for (unsigned i = 0; ; ++i) {
|
||||||
if (Command.C.Type == macho::LCT_FunctionStarts) {
|
if (Command.C.Type == macho::LCT_FunctionStarts) {
|
||||||
// We found a function starts segment, parse the addresses for later
|
// We found a function starts segment, parse the addresses for later
|
||||||
// consumption.
|
// consumption.
|
||||||
|
@ -214,7 +214,11 @@ getSectionsAndSymbols(const macho::Header Header,
|
||||||
|
|
||||||
MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
|
MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
|
||||||
}
|
}
|
||||||
Command = MachOObj->getNextLoadCommandInfo(Command);
|
|
||||||
|
if (i == Header.NumLoadCommands - 1)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
Command = MachOObj->getNextLoadCommandInfo(Command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue