pkg/tlsf: fix possible overflow in calloc implementation
This commit is contained in:
parent
75edf89a12
commit
84169266b4
@ -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)
|
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) {
|
if (result != NULL) {
|
||||||
memset(result, 0, count * bytes);
|
memset(result, 0, size_total);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user