]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Keep the command line on the heap to avoid stack overflow.
authorPaul Smith <psmith@gnu.org>
Sun, 9 Sep 2012 23:25:07 +0000 (23:25 +0000)
committerPaul Smith <psmith@gnu.org>
Sun, 9 Sep 2012 23:25:07 +0000 (23:25 +0000)
Fixes Savannah bug #36451.

ChangeLog
job.c

index ba6ddaedc71c50d25883a70058a3a62899e1f5c9..78836309ee6156581779c77b11cd49c00bc645e4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-09-09  Paul Smith  <psmith@gnu.org>
 
+       * job.c (construct_command_argv_internal): Keep the command line
+       on the heap for very long lines.  Fixes Savannah bug #36451.
+
        * function.c (func_realpath): BSD realpath(3) doesn't fail if the
        file does not exist: use stat.  Fixes Savannah bug #35919.
 
diff --git a/job.c b/job.c
index 754576b11246e5eda4459b93f1eef04d52aabf5a..f7b7d5199fdc981e8bd1140b21184a62f1bfe943 100644 (file)
--- a/job.c
+++ b/job.c
@@ -2984,8 +2984,8 @@ construct_command_argv_internal (char *line, char **restp, char *shell,
        return new_argv;
       }
 
-    new_line = alloca ((shell_len*2) + 1 + sflags_len + 1
-                             + (line_len*2) + 1);
+    new_line = xmalloc ((shell_len*2) + 1 + sflags_len + 1
+                        + (line_len*2) + 1);
     ap = new_line;
     /* Copy SHELL, escaping any characters special to the shell.  If
        we don't escape them, construct_command_argv_internal will
@@ -3052,8 +3052,11 @@ construct_command_argv_internal (char *line, char **restp, char *shell,
        *ap++ = *p;
       }
     if (ap == new_line + shell_len + sflags_len + 2)
-      /* Line was empty.  */
-      return 0;
+      {
+        /* Line was empty.  */
+        free (new_line);
+        return 0;
+      }
     *ap = '\0';
 
 #ifdef WINDOWS32
@@ -3194,6 +3197,8 @@ construct_command_argv_internal (char *line, char **restp, char *shell,
       fatal (NILF, _("%s (line %d) Bad shell context (!unixy && !batch_mode_shell)\n"),
             __FILE__, __LINE__);
 #endif
+
+    free (new_line);
   }
 #endif /* ! AMIGA */