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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179848 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2013-04-19 11:36:47 +00:00
parent 4521019c6f
commit db5f927020
4 changed files with 16 additions and 4 deletions

View File

@ -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;
@ -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);
}
}