Stop the assembler from running out of memory when asked to generate a huge number...
authorNick Clifton <nickc@redhat.com>
Tue, 6 Dec 2016 15:31:14 +0000 (15:31 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 6 Dec 2016 15:31:14 +0000 (15:31 +0000)
PR gas/20901
* read.c (s_space): Place an upper limit on the number of spaces
generated.

gas/ChangeLog
gas/read.c

index bb6beb8..781e975 100644 (file)
@@ -1,5 +1,9 @@
 2016-12-06  Nick Clifton  <nickc@redhat.com>
 
+       PR gas/20901
+       * read.c (s_space): Place an upper limit on the number of spaces
+       generated.
+
        PR gas/20896
        * testsuite/gas/mmix/err-byte1.s: Adjust expected warning messages
        to account for patch to next_char_of_string.
index 0cc0d20..08b8846 100644 (file)
@@ -3394,11 +3394,20 @@ s_space (int mult)
        {
          offsetT i;
 
-         if (mult == 0)
-           mult = 1;
-         bytes = mult * exp.X_add_number;
-         for (i = 0; i < exp.X_add_number; i++)
-           emit_expr (&val, mult);
+         /* PR 20901: Check for excessive values.
+            FIXME: 1<<10 is an arbitrary limit.  Maybe use maxpagesize instead ?  */
+         if (exp.X_add_number < 0 || exp.X_add_number > (1 << 10))
+           as_bad (_("size value for s_space directive too large: %lx"),
+                   (long) exp.X_add_number);
+         else
+           {
+             if (mult == 0)
+               mult = 1;
+             bytes = mult * exp.X_add_number;
+
+             for (i = 0; i < exp.X_add_number; i++)
+               emit_expr (&val, mult);
+           }
        }
     }
   else