]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Handle overflow in __hcreate_r
authorOndřej Bílka <neleai@seznam.cz>
Sat, 11 Jul 2015 15:44:10 +0000 (17:44 +0200)
committerMike Frysinger <vapier@gentoo.org>
Tue, 16 Feb 2016 18:59:14 +0000 (13:59 -0500)
Hi,

As in bugzilla entry there is overflow in hsearch when looking for prime
number as SIZE_MAX - 1 is divisible by 5. We fix that by rejecting large
inputs before looking for prime.

* misc/hsearch_r.c (__hcreate_r): Handle overflow.

(cherry picked from commit 2f5c1750558fe64bac361f52d6827ab1bcfe52bc)
(cherry picked from commit 51e762570e41074a7d9be5b0ee8761f037fc6e68)

misc/hsearch_r.c

index 3a7c52682c53feda7b122de12bebf8fdde37c9ea..8b368cbfecd711361eaa49ef723c644e10d52253 100644 (file)
@@ -19,7 +19,7 @@
 #include <errno.h>
 #include <malloc.h>
 #include <string.h>
-
+#include <stdint.h>
 #include <search.h>
 
 /* [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
@@ -73,6 +73,13 @@ hcreate_r (nel, htab)
       return 0;
     }
 
+  if (nel >= SIZE_MAX / sizeof (_ENTRY))
+    {
+      __set_errno (ENOMEM);
+      return 0;
+    }
+
+
   /* There is still another table active. Return with error. */
   if (htab->table != NULL)
     return 0;