forked from pool/glibc
61 lines
1.7 KiB
Diff
61 lines
1.7 KiB
Diff
|
2013-09-11 Will Newton <will.newton@linaro.org>
|
||
|
|
||
|
[BZ #15857]
|
||
|
* malloc/malloc.c (__libc_memalign): Check the value of bytes
|
||
|
does not overflow.
|
||
|
|
||
|
[BZ #15856]
|
||
|
* malloc/malloc.c (__libc_valloc): Check the value of bytes
|
||
|
does not overflow.
|
||
|
|
||
|
[BZ #15855]
|
||
|
* malloc/malloc.c (__libc_pvalloc): Check the value of bytes
|
||
|
does not overflow.
|
||
|
|
||
|
Index: glibc-2.18/malloc/malloc.c
|
||
|
===================================================================
|
||
|
--- glibc-2.18.orig/malloc/malloc.c
|
||
|
+++ glibc-2.18/malloc/malloc.c
|
||
|
@@ -3015,6 +3015,13 @@ __libc_memalign(size_t alignment, size_t
|
||
|
/* Otherwise, ensure that it is at least a minimum chunk size */
|
||
|
if (alignment < MINSIZE) alignment = MINSIZE;
|
||
|
|
||
|
+ /* Check for overflow. */
|
||
|
+ if (bytes > SIZE_MAX - alignment - MINSIZE)
|
||
|
+ {
|
||
|
+ __set_errno (ENOMEM);
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+
|
||
|
arena_get(ar_ptr, bytes + alignment + MINSIZE);
|
||
|
if(!ar_ptr)
|
||
|
return 0;
|
||
|
@@ -3046,6 +3053,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))
|
||
|
@@ -3082,6 +3096,13 @@ __libc_pvalloc(size_t bytes)
|
||
|
size_t page_mask = GLRO(dl_pagesize) - 1;
|
||
|
size_t rounded_bytes = (bytes + page_mask) & ~(page_mask);
|
||
|
|
||
|
+ /* Check for overflow. */
|
||
|
+ if (bytes > SIZE_MAX - 2*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))
|