[llvm] [MachO] Fix copy-paste condition in bounds check (PR #100176)

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 11:44:47 PDT 2024


================
@@ -5193,7 +5193,7 @@ MachOObjectFile::getDyldChainedFixupTargets() const {
   const char *Symbols = Contents + Header.symbols_offset;
   const char *SymbolsEnd = Contents + DyldChainedFixups.datasize;
 
-  if (ImportsEnd > Symbols)
+  if (ImportsEnd > SymbolsEnd)
     return malformedError("bad chained fixups: imports end " +
                           Twine(ImportsEndOffset) + " extends past end " +
                           Twine(DyldChainedFixups.datasize));
----------------
nico wrote:

If I look at line 5201, form what I understand, a `{DyldChainedFixups.dataoff, DyldChainedFixups.datasize }` span first contains a span of Imports, and following it a span of Symbols (in valid files). Is that correct?

If so, the `if (ImportsEnd > Symbols)` check in line 5201 makes sure that the Imports span is in fact in front of Symbols, and even after this patch this if here can never be true (?) Or did I get this wrong?

https://github.com/llvm/llvm-project/pull/100176


More information about the llvm-commits mailing list