From: Aurelien Jarno <aurelien@aurel32.net>
To: libc-stable@sourceware.org
Cc: "Ondřej Bílka" <neleai@seznam.cz>
Subject: [COMMITTED 2.22] Handle overflow in __hcreate_r
Date: Fri, 01 Jan 2016 00:00:00 -0000 [thread overview]
Message-ID: <1454150677-7735-1-git-send-email-aurelien@aurel32.net> (raw)
From: OndÅej BÃlka <neleai@seznam.cz>
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)
---
ChangeLog | 5 +++++
misc/hsearch_r.c | 9 ++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 9740c89..e818995 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-08-25 OndÅej BÃlka <neleai@seznam.cz>
+
+ [BZ #18240]
+ * misc/hsearch_r.c (__hcreate_r): Handle overflow.
+
2015-10-27 Ludovic Courtès <ludo@gnu.org>
* locale/loadlocale.c (_nl_intern_locale_data): Change assertion
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;
--
2.7.0.rc3
next reply other threads:[~2016-01-30 10:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-01 0:00 Aurelien Jarno [this message]
2016-01-01 0:00 ` [COMMITTED 2.22] Improve check against integer wraparound in hcreate_r [BZ #18240] Aurelien Jarno
2016-01-01 0:00 ` [COMMITTED 2.22] Handle overflow in __hcreate_r Tulio Magno Quites Machado Filho
2016-01-01 0:00 ` Mike Frysinger
2016-01-01 0:00 ` Tulio Magno Quites Machado Filho
2016-01-01 0:00 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1454150677-7735-1-git-send-email-aurelien@aurel32.net \
--to=aurelien@aurel32.net \
--cc=libc-stable@sourceware.org \
--cc=neleai@seznam.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).