[klibc] malloc: Fail if block size is out of range for sbrk

sbrk() takes a parameter of type intptr_t.  We allow allocating up to
PTRDIFF_MAX (equal to INPTPTR_MAX), and then add a header to that, so
the result fsize can be > INTPTR_MAX.  The conversion of fsize to
intptr_t would then result in undefined behaviour (but probably
*lowering* the top of heap).  Fail cleanly before that happens.

This is currently a theoretical problem since we actually use mmap()
instead of sbrk() on all architectures.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 file changed