+2019-11-06 Christian Eggers <ceggers@gmx.de>
+
+ * readelf.c (IN_RANGE): Rename parameter OFF to NELEM. Add
+ comment. Catch potential integer overflow and fix off by one
+ error whilst checking reloc location against section size.
+ (apply_relocations): Use IN_RANGE macro.
+
2019-11-04 Fangrui Song <maskray@google.com>
* objcopy.c (enum option_values): Add OPTION_KEEP_SECTION.
return TRUE;
}
-#define IN_RANGE(START,END,ADDR,OFF) \
- (((ADDR) >= (START)) && ((ADDR) + (OFF) < (END)))
+/* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
+ is contained by the region START .. END. The types of ADDR, START
+ and END should all be the same. Note both ADDR + NELEM and END
+ point to just beyond the end of the regions that are being tested. */
+#define IN_RANGE(START,END,ADDR,NELEM) \
+ (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
/* Check to see if the given reloc needs to be handled in a target specific
manner. If so then process the reloc and return TRUE otherwise return
}
rloc = start + rp->r_offset;
- if (rloc >= end || (rloc + reloc_size) > end || (rloc < start))
+ if (!IN_RANGE (start, end, rloc, reloc_size))
{
warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
(unsigned long) rp->r_offset,