[MachO] Fix detecting malformed DWARF.
authorIgor Kudrin <ikudrin@accesssoftek.com>
Mon, 16 Dec 2019 14:16:14 +0000 (21:16 +0700)
committerIgor Kudrin <ikudrin@accesssoftek.com>
Tue, 17 Dec 2019 08:03:23 +0000 (15:03 +0700)
This fixes an invalid constant used to detect the reserved range when
reading the compilation unit header. See also: D64622 and D65039.

Differential Revision: https://reviews.llvm.org/D71546

lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp

index 0163c90..6f294b1 100644 (file)
@@ -879,11 +879,11 @@ readCompUnit(const NormalizedFile &normalizedFile,
   llvm::dwarf::DwarfFormat Format = llvm::dwarf::DwarfFormat::DWARF32;
   auto infoData = dataExtractorFromSection(normalizedFile, info);
   uint32_t length = infoData.getU32(&offset);
-  if (length == 0xffffffff) {
+  if (length == llvm::dwarf::DW_LENGTH_DWARF64) {
     Format = llvm::dwarf::DwarfFormat::DWARF64;
     infoData.getU64(&offset);
   }
-  else if (length > 0xffffff00)
+  else if (length >= llvm::dwarf::DW_LENGTH_lo_reserved)
     return llvm::make_error<GenericError>("Malformed DWARF in " + path);
 
   uint16_t version = infoData.getU16(&offset);