From 1fdd89a78dfa4f0ea4b14c994a055de802e61a89 Mon Sep 17 00:00:00 2001
From: Ulrich Drepper <drepper@redhat.com>
Date: Fri, 30 Jan 2009 17:47:23 +0000
Subject: * malloc/malloc.c (sYSMALLOc): Don't use assert when detecting

	manipulated brk, use malloc_printerr.
	* misc/sbrk.c (__sbrk): Better error handling for nonsense
	requests.
---
 misc/sbrk.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

(limited to 'misc')

diff --git a/misc/sbrk.c b/misc/sbrk.c
index 0df6007..985b347 100644
--- a/misc/sbrk.c
+++ b/misc/sbrk.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,1995,1996,1997,2000,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1995-1997,2000,2002,2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -16,8 +16,9 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-#include <unistd.h>
 #include <errno.h>
+#include <stdint.h>
+#include <unistd.h>
 
 /* Defined in brk.c.  */
 extern void *__curbrk;
@@ -47,7 +48,10 @@ __sbrk (intptr_t increment)
     return __curbrk;
 
   oldbrk = __curbrk;
-  if (__brk (oldbrk + increment) < 0)
+  if ((increment > 0
+       ? ((uintptr_t) oldbrk + (uintptr_t) increment < (uintptr_t) oldbrk)
+       : ((uintptr_t) oldbrk < (uintptr_t) -increment))
+      || __brk (oldbrk + increment) < 0)
     return (void *) -1;
 
   return oldbrk;
-- 
cgit v1.1