aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorOndřej Bílka <neleai@seznam.cz>2015-07-11 17:44:10 +0200
committerAurelien Jarno <aurelien@aurel32.net>2016-01-29 18:38:16 +0100
commitb5cba5cff937e5336ff23380785da80cab09146c (patch)
treee5f52058945bd1d76aa3ebdd37ed0a6e744455f5 /misc
parentfd6e33ebd157966fed025a8cf68f2f0835dcbf02 (diff)
downloadglibc-b5cba5cff937e5336ff23380785da80cab09146c.zip
glibc-b5cba5cff937e5336ff23380785da80cab09146c.tar.gz
glibc-b5cba5cff937e5336ff23380785da80cab09146c.tar.bz2
Handle overflow in __hcreate_r
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)
Diffstat (limited to 'misc')
-rw-r--r--misc/hsearch_r.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/misc/hsearch_r.c b/misc/hsearch_r.c
index 81c27d8..4414a25 100644
--- a/misc/hsearch_r.c
+++ b/misc/hsearch_r.c
@@ -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;