mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-06 22:44:38 +08:00
mem_calloc: check for mem_size_t overflow when multiplying 2 mem_size_t input values
This commit is contained in:
parent
6fe66771cb
commit
e65a0950b2
@ -765,12 +765,18 @@ void *
|
|||||||
mem_calloc(mem_size_t count, mem_size_t size)
|
mem_calloc(mem_size_t count, mem_size_t size)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
size_t alloc_size = (size_t)count * (size_t)size;
|
||||||
|
|
||||||
|
if ((size_t)(mem_size_t)alloc_size != alloc_size) {
|
||||||
|
LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("mem_calloc: could not allocate %"SZT_F" bytes\n", alloc_size));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* allocate 'count' objects of size 'size' */
|
/* allocate 'count' objects of size 'size' */
|
||||||
p = mem_malloc(count * size);
|
p = mem_malloc((mem_size_t)alloc_size);
|
||||||
if (p) {
|
if (p) {
|
||||||
/* zero the memory */
|
/* zero the memory */
|
||||||
memset(p, 0, (size_t)count * (size_t)size);
|
memset(p, 0, alloc_size);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user