mirror of
https://git.proxmox.com/git/wasi-libc
synced 2025-08-14 14:28:15 +00:00
Make calloc set ENOMEM when failing due to overflow.
This fixes a bug in upstream dlmalloc, where it doesn't set errno to ENOMEM in overflow or footprint overrun cases.
This commit is contained in:
parent
972067b74b
commit
0df6243d52
@ -4055,12 +4055,26 @@ static void* sys_alloc(mstate m, size_t nb) {
|
||||
}
|
||||
|
||||
asize = granularity_align(nb + SYS_ALLOC_PADDING);
|
||||
#ifdef __wasilibc_unmodified_upstream // Bug fix: set ENOMEM on size overflow
|
||||
if (asize <= nb)
|
||||
return 0; /* wraparound */
|
||||
#else
|
||||
if (asize <= nb) {
|
||||
MALLOC_FAILURE_ACTION;
|
||||
return 0; /* wraparound */
|
||||
}
|
||||
#endif
|
||||
if (m->footprint_limit != 0) {
|
||||
size_t fp = m->footprint + asize;
|
||||
#ifdef __wasilibc_unmodified_upstream // Bug fix: set ENOMEM on footprint overrun
|
||||
if (fp <= m->footprint || fp > m->footprint_limit)
|
||||
return 0;
|
||||
#else
|
||||
if (fp <= m->footprint || fp > m->footprint_limit) {
|
||||
MALLOC_FAILURE_ACTION;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user