~mirabilos/klibc/master

Viewing all changes in revision 2183.

  • Committer: Ben Hutchings
  • Date: 2021-04-29 14:02:58 UTC
  • Revision ID: git-v1:abe5c3477ffa5e91029ef040aede622145dcc777
[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>

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: