]> granicus.if.org Git - llvm/commitdiff
[llvm-objdump] Don't disassemble symbols before SectionAddr
authorFangrui Song <maskray@google.com>
Sat, 20 Apr 2019 07:19:24 +0000 (07:19 +0000)
committerFangrui Song <maskray@google.com>
Sat, 20 Apr 2019 07:19:24 +0000 (07:19 +0000)
This was caught by UBSAN

tools/llvm-objdump/X86/macho-disassembly-g-dsym.test
tools/llvm-objdump/X86/hex-displacement.test

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358806 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-objdump/llvm-objdump.cpp

index fb12e750fc6b8413ea09bdc567b98b6ff8ef71b9..37b17cb2f4a84cdb68904d50cc47f350a1f01acc 100644 (file)
@@ -1148,13 +1148,15 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
         continue;
 
       uint64_t Start = std::get<0>(Symbols[SI]);
+      if (Start < SectionAddr || StopAddress <= Start)
+        continue;
 
       // The end is the section end, the beginning of the next symbol, or
       // --stop-address.
-      uint64_t End = std::min<uint64_t>(SectionAddr + SectSize, StopAddress);
-      if (SI + 1 < SE)
-        End = std::min(End, std::get<0>(Symbols[SI + 1]));
-      if (Start >= End || Start >= StopAddress || End <= StartAddress)
+      uint64_t End = std::min<uint64_t>(
+          SI + 1 < SE ? std::get<0>(Symbols[SI + 1]) : SectionAddr + SectSize,
+          StopAddress);
+      if (Start >= End || End <= StartAddress)
         continue;
       Start -= SectionAddr;
       End -= SectionAddr;