[llvm] r179848 - Don't read one command past the end.
Eric Christopher
echristo at gmail.com
Mon Apr 22 03:29:11 PDT 2013
On Fri, Apr 19, 2013 at 4:36 AM, Rafael Espindola
<rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Fri Apr 19 06:36:47 2013
> New Revision: 179848
>
> URL: http://llvm.org/viewvc/llvm-project?rev=179848&view=rev
> Log:
> 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.
>
I added one into all of the interfaces :)
-eric
> Added:
> llvm/trunk/test/Object/ARM/objdump-thumb.test
> llvm/trunk/test/Object/Inputs/macho-text.thumb
> Modified:
> llvm/trunk/lib/Object/MachOObjectFile.cpp
> llvm/trunk/tools/llvm-objdump/MachODump.cpp
>
> Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=179848&r1=179847&r2=179848&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/MachOObjectFile.cpp Fri Apr 19 06:36:47 2013
> @@ -405,7 +405,7 @@ MachOObjectFile::MachOObjectFile(MemoryB
> 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(MemoryB
> Sections.push_back(reinterpret_cast<const char*>(Sec));
> }
> }
> - Load = getNextLoadCommandInfo(Load);
> +
> + if (I == LoadCommandCount - 1)
> + break;
> + else
> + Load = getNextLoadCommandInfo(Load);
> }
> }
>
>
> Added: llvm/trunk/test/Object/ARM/objdump-thumb.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/ARM/objdump-thumb.test?rev=179848&view=auto
> ==============================================================================
> --- llvm/trunk/test/Object/ARM/objdump-thumb.test (added)
> +++ llvm/trunk/test/Object/ARM/objdump-thumb.test Fri Apr 19 06:36:47 2013
> @@ -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
>
> Added: llvm/trunk/test/Object/Inputs/macho-text.thumb
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/macho-text.thumb?rev=179848&view=auto
> ==============================================================================
> Binary files llvm/trunk/test/Object/Inputs/macho-text.thumb (added) and llvm/trunk/test/Object/Inputs/macho-text.thumb Fri Apr 19 06:36:47 2013 differ
>
> Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=179848&r1=179847&r2=179848&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
> +++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Fri Apr 19 06:36:47 2013
> @@ -205,7 +205,7 @@ getSectionsAndSymbols(const macho::Heade
>
> 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.
> @@ -214,7 +214,11 @@ getSectionsAndSymbols(const macho::Heade
>
> MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
> }
> - Command = MachOObj->getNextLoadCommandInfo(Command);
> +
> + if (i == Header.NumLoadCommands - 1)
> + break;
> + else
> + Command = MachOObj->getNextLoadCommandInfo(Command);
> }
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list