[v2] sprof: check pread size and offset for overflow
Collin Funk
collin.funk1@gmail.com
Fri Oct 17 01:26:15 GMT 2025
DJ Delorie <dj@redhat.com> writes:
> Collin Funk <collin.funk1@gmail.com> writes:
>> Generally, I prefer to avoid writing overflow checks manually since it
>
> Checking for overflow is NOT one of the things I'm worried about. It's
> not one of the things I'm expecting or checking for.
>
> I'm checking that all the values are in the range [0..filesize].
Right, you mentioned that in another mail. But I did not address it, my
apologies.
I think that we should check for overflows in this case. I could
construct an ELF file where the following expression overflows:
(ehdr->e_shnum * sizeof (ElfW (Shdr)) + ehdr->e_shoff
Even though a real ELF file would almost certainly not cause this, I
think it is better to throw a meaningful error instead of continuing
with an integer that has wrapped around, or undefined behavior in the
case they are casted to signed integers like your patch.
Collin
More information about the Libc-alpha
mailing list