changeset 37268:0f5de719ab07

(align): If the argument SIZE would overflow __malloc_ptrdiff_t, fail right away.
author Eli Zaretskii <eliz@gnu.org>
date Mon, 09 Apr 2001 10:52:43 +0000
parents 4c866979fd95
children cdc3247d50f2
files src/gmalloc.c
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/gmalloc.c	Mon Apr 09 09:58:37 2001 +0000
+++ b/src/gmalloc.c	Mon Apr 09 10:52:43 2001 +0000
@@ -437,7 +437,14 @@
   __ptr_t result;
   unsigned long int adj;
 
-  result = (*__morecore) (size);
+  /* align accepts an unsigned argument, but __morecore accepts a
+     signed one.  This could lead to trouble if SIZE overflows a
+     signed int type accepted by __morecore.  We just punt in that
+     case, since they are requesting a ludicrous amount anyway.  */
+  if ((__malloc_ptrdiff_t)size < 0)
+    result = 0;
+  else
+    result = (*__morecore) (size);
   adj = (unsigned long int) ((unsigned long int) ((char *) result -
 						  (char *) NULL)) % BLOCKSIZE;
   if (adj != 0)