[BZ,#18240] Handle overflow in __hcreate_r
Commit Message
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.
Comments
On Sat, Jul 11, 2015 at 05:44:10PM +0200, Ondřej Bílka wrote:
> 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.
Looks OK to me.
Siddhesh
@@ -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;