mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
This got lost last year
The missing calloc() overflow test never made it to the CVS or git repositories :-(
This commit is contained in:
@ -59,13 +59,25 @@ __calloc(size_t num_elements,size_t element_size,const char * file,int line)
|
|||||||
}
|
}
|
||||||
#endif /* __MEM_DEBUG */
|
#endif /* __MEM_DEBUG */
|
||||||
|
|
||||||
|
/* This might overflow. */
|
||||||
total_size = num_elements * element_size;
|
total_size = num_elements * element_size;
|
||||||
|
|
||||||
result = __malloc(total_size,file,line);
|
/* No arithmetic overflow? */
|
||||||
if(result != NULL)
|
if(total_size >= num_elements)
|
||||||
memset(result,0,total_size);
|
{
|
||||||
|
result = __malloc(total_size,file,line);
|
||||||
|
if(result != NULL)
|
||||||
|
memset(result,0,total_size);
|
||||||
|
else
|
||||||
|
SHOWMSG("memory allocation failure");
|
||||||
|
}
|
||||||
|
/* Multiplying the number and size of elements overflows
|
||||||
|
* the size_t range.
|
||||||
|
*/
|
||||||
else
|
else
|
||||||
SHOWMSG("memory allocation failure");
|
{
|
||||||
|
D(("calloc(num_elements=%ld, element_size=%ld) overflow"));
|
||||||
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user