Correctly handle the case in calloc(num, size) where

(size_t)(num * size) == 0
but both num and size are nonzero.

Reported by:	Ilja van Sprundel
Approved by:	jasone
Security:	Integer overflow; calloc was allocating 1 byte in
		response to a request for a multiple of 2^32 (or 2^64)
		bytes instead of returning NULL.
This commit is contained in:
Colin Percival 2006-08-13 21:54:47 +00:00
parent 0f9e9c60c0
commit e981a4e863

View file

@ -3495,7 +3495,7 @@ calloc(size_t num, size_t size)
num_size = num * size;
if (num_size == 0) {
if (opt_sysv == false)
if ((opt_sysv == false) && ((num == 0) || (size == 0)))
num_size = 1;
else {
ret = NULL;