Prevent allocations of size 0 in sh_init, which are not possible with the default...
authorGuido Vranken <guidovranken@gmail.com>
Mon, 13 Feb 2017 00:36:43 +0000 (01:36 +0100)
committerRich Salz <rsalz@openssl.org>
Tue, 14 Feb 2017 19:28:34 +0000 (14:28 -0500)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2605)

crypto/mem_sec.c

index 4ccff34e5e8fa71a4929cfbc6008eaebe3bb3ddd..0c79b43658c326e13f4917de5f3ce914b2168859 100644 (file)
@@ -356,6 +356,10 @@ static int sh_init(size_t size, int minsize)
     sh.minsize = minsize;
     sh.bittable_size = (sh.arena_size / sh.minsize) * 2;
 
+    /* Prevent allocations of size 0 later on */
+    if (sh.bittable_size >> 3 == 0)
+        goto err;
+
     sh.freelist_size = -1;
     for (i = sh.bittable_size; i; i >>= 1)
         sh.freelist_size++;