[v2] sprof: check pread size and offset for overflow
Paul Eggert
eggert@cs.ucla.edu
Fri Oct 17 16:04:38 GMT 2025
On 2025-10-16 16:59, DJ Delorie wrote:
>> What you're trying to say here, is that SZ and OFF are both nonnegative,
>> and that their sum is less than ST.st_size.
> AND that the values we read from the ELF file are reasonable. That
> includes checking each against st.st_size.
The former implies the latter. Once you've checked that 0<=OFF & 0<=SZ &
OFF+SZ<=FILESIZE, you've also checked that OFF<=FILESIZE and
SZ<=FILESIZE. There is no need to check separately that OFF<=FILESIZE or
that SZ<=FILESIZE.
More generally, integer overflows are a Big Deal. They are worth
checking for in any software requiring reliability or security (Collin's
recent email gives an example). And once you check for integer
overflows, some other checks become unnecessary.
More information about the Libc-alpha
mailing list