Skip to content

Commit 5748c64

Browse files
committed
Fix integer overflow in boundary checking
This commit prevents arithmetic underflow in the size validation check that could bypass TLSF_MAX_SIZE limits. When align + sizeof(tlsf_block_t) exceeds TLSF_MAX_SIZE, the original expression would underflow and incorrectly pass the size check, potentially allowing oversized allocations.
1 parent cf7c846 commit 5748c64

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tlsf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ void *tlsf_aalloc(tlsf_t *t, size_t align, size_t size)
498498
if (UNLIKELY(
499499
!size ||
500500
((align | size) & (align - 1)) /* align!=2**x, size!=n*align */ ||
501-
adjust > TLSF_MAX_SIZE - align -
502-
sizeof(tlsf_block_t) /* size is too large */))
501+
align > TLSF_MAX_SIZE || sizeof(tlsf_block_t) > TLSF_MAX_SIZE ||
502+
adjust > TLSF_MAX_SIZE - align - sizeof(tlsf_block_t) /* size is too large */))
503503
return NULL;
504504

505505
if (align <= ALIGN_SIZE)

0 commit comments

Comments
 (0)