Check whether requested memory size fits in object datum.
authorTaylor R Campbell <campbell@mumble.net>
Thu, 28 Apr 2011 05:37:04 +0000 (05:37 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Thu, 28 Apr 2011 05:43:22 +0000 (05:43 +0000)
Do this before even trying to allocate the memory.

src/microcode/memmag.c

index d656203cd96632552224293e630f61a8786a8a57..82f535e35e57d5fd469e237b02b9e3221886b309 100644 (file)
@@ -120,12 +120,16 @@ setup_memory (unsigned long heap_size,
       exit (1);
     }
 
+  /* Consistency check 2 */
+  if ((stack_size + heap_size + constant_size) >= DATUM_MASK)
+    goto allocation_too_large;
+
   /* Allocate */
   ALLOCATE_HEAP_SPACE ((stack_size + heap_size + constant_size),
                       memory_block_start,
                       memory_block_end);
 
-  /* Consistency check 2 */
+  /* Consistency check 3 */
   if (memory_block_start == 0)
     {
       outf_fatal ("Not enough memory for this configuration.\n");
@@ -133,9 +137,10 @@ setup_memory (unsigned long heap_size,
       exit (1);
     }
 
-  /* Consistency check 3 */
+  /* Consistency check 4 */
   if ((ADDRESS_TO_DATUM (memory_block_end)) > DATUM_MASK)
     {
+    allocation_too_large:
       outf_fatal ("Requested allocation is too large.\n");
       outf_fatal ("Try again with a smaller argument to '--heap'.\n");
       outf_flush_fatal ();