12745e
diff --git glibc-2.17-c758a686/malloc/malloc.c glibc-2.17-c758a686/malloc/malloc.c
29e444
index 3148c5f..f7718a9 100644
12745e
--- glibc-2.17-c758a686/malloc/malloc.c
12745e
+++ glibc-2.17-c758a686/malloc/malloc.c
29e444
@@ -3015,6 +3015,13 @@ __libc_memalign(size_t alignment, size_t bytes)
29e444
   /* Otherwise, ensure that it is at least a minimum chunk size */
29e444
   if (alignment <  MINSIZE) alignment = MINSIZE;
29e444
 
29e444
+  /* Check for overflow.  */
29e444
+  if (bytes > SIZE_MAX - alignment - MINSIZE)
29e444
+    {
29e444
+      __set_errno (ENOMEM);
29e444
+      return 0;
29e444
+    }
29e444
+
29e444
   arena_get(ar_ptr, bytes + alignment + MINSIZE);
29e444
   if(!ar_ptr)
29e444
     return 0;
29e444
@@ -3046,6 +3046,13 @@ __libc_valloc(size_t bytes)
29e444
 
29e444
   size_t pagesz = GLRO(dl_pagesize);
29e444
 
29e444
+  /* Check for overflow.  */
29e444
+  if (bytes > SIZE_MAX - pagesz - MINSIZE)
29e444
+    {
29e444
+      __set_errno (ENOMEM);
29e444
+      return 0;
29e444
+    }
29e444
+
29e444
   __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
29e444
 					const __malloc_ptr_t)) =
29e444
     force_reg (__memalign_hook);
29e444
@@ -3082,6 +3082,13 @@ __libc_pvalloc(size_t bytes)
29e444
   size_t page_mask = GLRO(dl_pagesize) - 1;
29e444
   size_t rounded_bytes = (bytes + page_mask) & ~(page_mask);
29e444
 
29e444
+  /* Check for overflow.  */
29e444
+  if (bytes > SIZE_MAX - 2*pagesz - MINSIZE)
29e444
+    {
29e444
+      __set_errno (ENOMEM);
29e444
+      return 0;
29e444
+    }
29e444
+
29e444
   __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
29e444
 					const __malloc_ptr_t)) =
29e444
     force_reg (__memalign_hook);