summaryrefslogtreecommitdiff
path: root/libc/malloc/hooks.c
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2013-10-18 21:33:25 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2013-10-18 21:33:25 +0000
commitfe2ed5aaa408e1ab996a9fe1595a05634208a79c (patch)
treee1027fbc9d8a4a8c33f8149b2b42e8cde89c74f6 /libc/malloc/hooks.c
parent571c782b982d888565e7d06bfc2f3d47582fe829 (diff)
downloadeglibc2-fe2ed5aaa408e1ab996a9fe1595a05634208a79c.tar.gz
Merge changes between r23946 and r24305 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@24306 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/malloc/hooks.c')
-rw-r--r--libc/malloc/hooks.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libc/malloc/hooks.c b/libc/malloc/hooks.c
index 8c2584633..3f663bb6b 100644
--- a/libc/malloc/hooks.c
+++ b/libc/malloc/hooks.c
@@ -361,10 +361,13 @@ memalign_check(size_t alignment, size_t bytes, const void *caller)
if (alignment <= MALLOC_ALIGNMENT) return malloc_check(bytes, NULL);
if (alignment < MINSIZE) alignment = MINSIZE;
- if (bytes+1 == 0) {
- __set_errno (ENOMEM);
- return NULL;
- }
+ /* Check for overflow. */
+ if (bytes > SIZE_MAX - alignment - MINSIZE)
+ {
+ __set_errno (ENOMEM);
+ return 0;
+ }
+
(void)mutex_lock(&main_arena.mutex);
mem = (top_check() >= 0) ? _int_memalign(&main_arena, alignment, bytes+1) :
NULL;