llvm.org GIT mirror llvm / d682839
Don't loop endlessly for MachO files with 0 ncmds git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225271 91177308-0d34-0410-b5e6-96231b3b80d8 Filipe Cabecinhas 4 years ago
4 changed file(s) with 14 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
235235 DataInCodeLoadCmd(nullptr), DyldInfoLoadCmd(nullptr),
236236 UuidLoadCmd(nullptr), HasPageZeroSegment(false) {
237237 uint32_t LoadCommandCount = this->getHeader().ncmds;
238 if (LoadCommandCount == 0)
239 return;
240
238241 MachO::LoadCommandType SegmentLoadType = is64Bit() ?
239242 MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT;
240243
0 RUN: llvm-objdump -private-headers %p/Inputs/macho-zero-ncmds \
1 RUN: | FileCheck %s -check-prefix A
2
3 // Check that we don't get an infinite loop if ncmds = 0
4 A: file format Mach-O 64-bit unknown
5 A: Mach header
6 A: magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
7 A: MH_MAGIC_64 0x00 OBJECT 0 0 0x00000000
8
42034203 static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds,
42044204 uint32_t filetype, uint32_t cputype,
42054205 bool verbose) {
4206 if (ncmds == 0)
4207 return;
42064208 StringRef Buf = Obj->getData();
42074209 MachOObjectFile::LoadCommandInfo Command = Obj->getFirstLoadCommandInfo();
42084210 for (unsigned i = 0;; ++i) {