]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Do not divide by zero.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 20 Mar 2015 16:03:14 +0000 (16:03 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 20 Mar 2015 16:03:14 +0000 (16:03 +0000)
git-svn-id: file:///svn/unbound/trunk@3374 be551aaa-1e26-0410-a405-d3ace91eadb9

util/alloc.c

index a23c6d57e8e14f78aae11d212b5139e1fc9cb4ed..66bdc7db9ada6a8cc809a03f217adc9156190f6b 100644 (file)
@@ -369,7 +369,7 @@ void *unbound_stat_calloc(size_t nmemb, size_t size)
 {
        size_t s;
        void* res;
-       if(INT_MAX/nmemb < size)
+       if(nmemb != 0 && INT_MAX/nmemb < size)
                return NULL; /* integer overflow check */
        s = (nmemb*size==0)?(size_t)1:nmemb*size;
        res = calloc(1, s+16);
@@ -509,7 +509,7 @@ void *unbound_stat_calloc_lite(size_t nmemb, size_t size, const char* file,
 {
        size_t req;
        void* res;
-       if(INT_MAX/nmemb < size)
+       if(nmemb != 0 && INT_MAX/nmemb < size)
                return NULL; /* integer overflow check */
        req = nmemb * size;
        res = malloc(req+lite_pad*2+sizeof(size_t));