diff options
author | Will Newton <will.newton@linaro.org> | 2013-08-16 11:59:37 +0100 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2014-01-06 08:42:47 -0500 |
commit | 42b872e43db7c71cd40357724f1542252eb0c708 (patch) | |
tree | 8d119334613f0512dc1119655753fadf1ecefc0d | |
parent | 7e52cc7af467b6a8ba6367af4fecd4c3289db454 (diff) | |
download | glibc-42b872e43db7c71cd40357724f1542252eb0c708.tar glibc-42b872e43db7c71cd40357724f1542252eb0c708.tar.gz glibc-42b872e43db7c71cd40357724f1542252eb0c708.tar.bz2 glibc-42b872e43db7c71cd40357724f1542252eb0c708.zip |
malloc: Check for integer overflow in valloc.
A large bytes parameter to valloc could cause an integer overflow
and corrupt allocator internals. Check the overflow does not occur
before continuing with the allocation.
ChangeLog:
2013-09-11 Will Newton <will.newton@linaro.org>
[BZ #15856]
* malloc/malloc.c (__libc_valloc): Check the value of bytes
does not overflow.
(cherry picked from commit 6a6a386a3040726053a5fb8582ff26dc85d84741)
-rw-r--r-- | malloc/malloc.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c index bcc08c45f7..31e2dfad91 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3046,6 +3046,13 @@ __libc_valloc(size_t bytes) size_t pagesz = GLRO(dl_pagesize); + /* Check for overflow. */ + if (bytes > SIZE_MAX - pagesz - MINSIZE) + { + __set_errno (ENOMEM); + return 0; + } + void *(*hook) (size_t, size_t, const void *) = force_reg (__memalign_hook); if (__builtin_expect (hook != NULL, 0)) |