nalika / rpms / bash

Forked from rpms/bash 2 years ago
Clone
462fb2
--- ../bash-4.2-orig/parse.y	2014-09-25 13:07:59.218209276 +0200
462fb2
+++ parse.y	2014-09-25 15:26:52.813159810 +0200
462fb2
@@ -264,9 +264,21 @@
462fb2
 
462fb2
 /* Variables to manage the task of reading here documents, because we need to
462fb2
    defer the reading until after a complete command has been collected. */
462fb2
-static REDIRECT *redir_stack[10];
462fb2
+static REDIRECT **redir_stack;
462fb2
 int need_here_doc;
462fb2
 
462fb2
+/* Pushes REDIR onto redir_stack, resizing it as needed. */
462fb2
+static void
462fb2
+push_redir_stack (REDIRECT *redir)
462fb2
+{
462fb2
+  /* Guard against oveflow. */
462fb2
+  if (need_here_doc + 1 > INT_MAX / sizeof (*redir_stack))
462fb2
+    abort ();
462fb2
+  redir_stack = xrealloc (redir_stack,
462fb2
+			  (need_here_doc + 1) * sizeof (*redir_stack));
462fb2
+  redir_stack[need_here_doc++] = redir;
462fb2
+}
462fb2
+
462fb2
 /* Where shell input comes from.  History expansion is performed on each
462fb2
    line when the shell is interactive. */
462fb2
 static char *shell_input_line = (char *)NULL;
462fb2
@@ -519,42 +531,42 @@
462fb2
 			  source.dest = 0;
462fb2
 			  redir.filename = $2;
462fb2
 			  $$ = make_redirection (source, r_reading_until, redir, 0);
462fb2
-			  redir_stack[need_here_doc++] = $$;
462fb2
+			  push_redir_stack ($$);
462fb2
 			}
462fb2
 	|	NUMBER LESS_LESS WORD
462fb2
 			{
462fb2
 			  source.dest = $1;
462fb2
 			  redir.filename = $3;
462fb2
 			  $$ = make_redirection (source, r_reading_until, redir, 0);
462fb2
-			  redir_stack[need_here_doc++] = $$;
462fb2
+			  push_redir_stack ($$);
462fb2
 			}
462fb2
 	|	REDIR_WORD LESS_LESS WORD
462fb2
 			{
462fb2
 			  source.filename = $1;
462fb2
 			  redir.filename = $3;
462fb2
 			  $$ = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN);
462fb2
-			  redir_stack[need_here_doc++] = $$;
462fb2
+			  push_redir_stack ($$);
462fb2
 			}
462fb2
 	|	LESS_LESS_MINUS WORD
462fb2
 			{
462fb2
 			  source.dest = 0;
462fb2
 			  redir.filename = $2;
462fb2
 			  $$ = make_redirection (source, r_deblank_reading_until, redir, 0);
462fb2
-			  redir_stack[need_here_doc++] = $$;
462fb2
+			  push_redir_stack ($$);
462fb2
 			}
462fb2
 	|	NUMBER LESS_LESS_MINUS WORD
462fb2
 			{
462fb2
 			  source.dest = $1;
462fb2
 			  redir.filename = $3;
462fb2
 			  $$ = make_redirection (source, r_deblank_reading_until, redir, 0);
462fb2
-			  redir_stack[need_here_doc++] = $$;
462fb2
+			  push_redir_stack ($$);
462fb2
 			}
462fb2
 	|	REDIR_WORD  LESS_LESS_MINUS WORD
462fb2
 			{
462fb2
 			  source.filename = $1;
462fb2
 			  redir.filename = $3;
462fb2
 			  $$ = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN);
462fb2
-			  redir_stack[need_here_doc++] = $$;
462fb2
+			  push_redir_stack ($$);
462fb2
 			}
462fb2
 	|	LESS_LESS_LESS WORD
462fb2
 			{
462fb2
@@ -4757,7 +4769,7 @@
462fb2
     case CASE:
462fb2
     case SELECT:
462fb2
     case FOR:
462fb2
-      if (word_top < MAX_CASE_NEST)
462fb2
+      if (word_top + 1 < MAX_CASE_NEST)
462fb2
 	word_top++;
462fb2
       word_lineno[word_top] = line_number;
462fb2
       break;