pkg/tlsf: fix possible overflow in calloc implementation

This commit is contained in:
Marian Buschsieweke 2021-05-04 14:10:15 +02:00
parent 75edf89a12
commit 84169266b4
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F

View File

@ -71,10 +71,14 @@ ATTR_MALLOCR void *_malloc_r(struct _reent *reent_ptr, size_t bytes)
*/
ATTR_CALLOCR void *_calloc_r(struct _reent *reent_ptr, size_t count, size_t bytes)
{
void *result = _malloc_r(reent_ptr, count * bytes);
size_t size_total;
if (__builtin_mul_overflow(count, bytes, &size_total)) {
return NULL;
}
void *result = _malloc_r(reent_ptr, size_total);
if (result != NULL) {
memset(result, 0, count * bytes);
memset(result, 0, size_total);
}
return result;
}