[llvm] r225271 - Don't loop endlessly for MachO files with 0 ncmds
Rafael EspĂndola
rafael.espindola at gmail.com
Tue Jan 6 16:02:33 PST 2015
Nice :-)
On 6 January 2015 at 12:08, Filipe Cabecinhas <me at filcab.net> wrote:
> Author: filcab
> Date: Tue Jan 6 11:08:26 2015
> New Revision: 225271
>
> URL: http://llvm.org/viewvc/llvm-project?rev=225271&view=rev
> Log:
> Don't loop endlessly for MachO files with 0 ncmds
>
> Added:
> llvm/trunk/test/Object/Inputs/macho-zero-ncmds
> llvm/trunk/test/Object/objdump-macho-quirks.test
> 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=225271&r1=225270&r2=225271&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/MachOObjectFile.cpp Tue Jan 6 11:08:26 2015
> @@ -236,6 +236,9 @@ MachOObjectFile::MachOObjectFile(MemoryB
> DataInCodeLoadCmd(nullptr), DyldInfoLoadCmd(nullptr),
> UuidLoadCmd(nullptr), HasPageZeroSegment(false) {
> uint32_t LoadCommandCount = this->getHeader().ncmds;
> + if (LoadCommandCount == 0)
> + return;
> +
> MachO::LoadCommandType SegmentLoadType = is64Bit() ?
> MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT;
>
>
> Added: llvm/trunk/test/Object/Inputs/macho-zero-ncmds
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/macho-zero-ncmds?rev=225271&view=auto
> ==============================================================================
> Binary files llvm/trunk/test/Object/Inputs/macho-zero-ncmds (added) and llvm/trunk/test/Object/Inputs/macho-zero-ncmds Tue Jan 6 11:08:26 2015 differ
>
> Added: llvm/trunk/test/Object/objdump-macho-quirks.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/objdump-macho-quirks.test?rev=225271&view=auto
> ==============================================================================
> --- llvm/trunk/test/Object/objdump-macho-quirks.test (added)
> +++ llvm/trunk/test/Object/objdump-macho-quirks.test Tue Jan 6 11:08:26 2015
> @@ -0,0 +1,9 @@
> +RUN: llvm-objdump -private-headers %p/Inputs/macho-zero-ncmds \
> +RUN: | FileCheck %s -check-prefix A
> +
> +// Check that we don't get an infinite loop if ncmds = 0
> +A: file format Mach-O 64-bit unknown
> +A: Mach header
> +A: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
> +A: MH_MAGIC_64 0x00 OBJECT 0 0 0x00000000
> +
>
> Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=225271&r1=225270&r2=225271&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
> +++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Tue Jan 6 11:08:26 2015
> @@ -4204,6 +4204,8 @@ static void PrintLinkEditDataCommand(Mac
> static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds,
> uint32_t filetype, uint32_t cputype,
> bool verbose) {
> + if (ncmds == 0)
> + return;
> StringRef Buf = Obj->getData();
> MachOObjectFile::LoadCommandInfo Command = Obj->getFirstLoadCommandInfo();
> for (unsigned i = 0;; ++i) {
>
>
> _______________________________________________
> 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