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

Daniel Bertalan via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 03:20:22 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));
----------------
BertalanD 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?

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?

this is checked *before* `ImportsEnd > Symbols`, so if `ImportsEnd` extends past the whole section (i.e. `SymbolsEnd`), this message will be printed instead of the one belonging to line 5201. But I agree that there is not much point in making this distinction. Let's just remove this one.

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


More information about the llvm-commits mailing list