From: Ondřej Bílka Date: Sat, 11 Jul 2015 15:44:10 +0000 (+0200) Subject: Handle overflow in __hcreate_r X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=24772ea8cd098a39bffe623417a2fa15f53d9ec8;p=thirdparty%2Fglibc.git 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) (cherry picked from commit 43f189b0032fbce67fc0c0f4e122e917cd232670) --- diff --git a/misc/hsearch_r.c b/misc/hsearch_r.c index 9f55e845cf7..559df29cf7b 100644 --- a/misc/hsearch_r.c +++ b/misc/hsearch_r.c @@ -19,7 +19,7 @@ #include #include #include - +#include #include /* [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;