* [PATCH][BZ #18240] Handle overflow in __hcreate_r
@ 2015-07-11 15:44 Ondřej Bílka
2015-07-15 11:16 ` Siddhesh Poyarekar
0 siblings, 1 reply; 2+ messages in thread
From: Ondřej Bílka @ 2015-07-11 15:44 UTC (permalink / raw)
To: libc-alpha
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.
diff --git a/misc/hsearch_r.c b/misc/hsearch_r.c
index 9f55e84..559df29 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;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH][BZ #18240] Handle overflow in __hcreate_r
2015-07-11 15:44 [PATCH][BZ #18240] Handle overflow in __hcreate_r Ondřej Bílka
@ 2015-07-15 11:16 ` Siddhesh Poyarekar
0 siblings, 0 replies; 2+ messages in thread
From: Siddhesh Poyarekar @ 2015-07-15 11:16 UTC (permalink / raw)
To: Ondřej Bílka; +Cc: libc-alpha
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-15 11:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-11 15:44 [PATCH][BZ #18240] Handle overflow in __hcreate_r Ondřej Bílka
2015-07-15 11:16 ` Siddhesh Poyarekar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).