Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
Date: 2010-02-24
Initial Package Version: 3.81
Upstream Status: From upstream
Origin: CVS
Description:

bug #27148: Use of strcpy on overlapping memory areas
http://savannah.gnu.org/bugs/?27148
http://cvs.savannah.gnu.org/viewvc/make/job.c?root=make&r1=1.194&r2=1.195

2009-08-01  Paul Smith  <psmith@gnu.org>
	* job.c (new_job): Use memmove() instead of strcpy() since both
	pointers are in the same memory block.  Fixes Savannah bug #27148.
	Patch by Petr Machata.

bug #22010: The increased stack rlimit is inherited by the subprocesses to make.
http://savannah.gnu.org/bugs/?22010
http://cvs.savannah.gnu.org/viewvc/make/make.h?root=make&r1=1.132&r2=1.133&view=patch
http://cvs.savannah.gnu.org/viewvc/make/main.c?root=make&r1=1.228&r2=1.229&view=patch
http://cvs.savannah.gnu.org/viewvc/make/job.c?root=make&r1=1.191&r2=1.192&view=patch

2009-06-07  Paul Smith  <psmith@gnu.org>
	* make.h: Move SET_STACK_SIZE determination to make.h.
	* main.c (main): New global variable, STACK_LIMIT, holds the
	original stack limit when make was started.
	* job.c (start_job_command): Reset the stack limit, if we changed it.
	Fixes Savannah bug #22010.

diff -Naur make-3.81.orig/job.c make-3.81/job.c
--- make-3.81.orig/job.c	2006-03-20 03:03:04.000000000 +0000
+++ make-3.81/job.c	2010-02-24 09:41:51.000000000 +0000
@@ -1275,6 +1275,12 @@
           if (job_rfd >= 0)
             close (job_rfd);
 
+#ifdef SET_STACK_SIZE
+          /* Reset limits, if necessary.  */
+          if (stack_limit.rlim_cur)
+            setrlimit (RLIMIT_STACK, &stack_limit);
+#endif
+
 	  child_execute_job (child->good_stdin ? 0 : bad_stdin, 1,
                              argv, child->environment);
 	}
@@ -1594,7 +1600,7 @@
       /* There are no more references in this line to worry about.
 	 Copy the remaining uninteresting text to the output.  */
       if (out != in)
-	strcpy (out, in);
+	memmove (out, in, strlen (in) + 1);
 
       /* Finally, expand the line.  */
       lines[i] = allocated_variable_expand_for_file (cmds->command_lines[i],
@@ -2237,7 +2243,7 @@
 				 "for", "case", "if", ":", ".", "break",
 				 "continue", "export", "read", "readonly",
 				 "shift", "times", "trap", "switch", "unset",
-                                 0 };
+                                 "ulimit", 0 };
 
   char *sh_chars;
   char **sh_cmds;
diff -Naur make-3.81.orig/main.c make-3.81/main.c
--- make-3.81.orig/main.c	2006-03-20 02:36:37.000000000 +0000
+++ make-3.81/main.c	2010-02-24 09:49:30.000000000 +0000
@@ -44,14 +44,6 @@
 # include <fcntl.h>
 #endif
 
-#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
-# define SET_STACK_SIZE
-#endif
-
-#ifdef SET_STACK_SIZE
-# include <sys/resource.h>
-#endif
-
 #ifdef _AMIGA
 int __stack = 20000; /* Make sure we have 20K of stack space */
 #endif
@@ -213,6 +205,13 @@
 
 static struct stringlist *makefiles = 0;
 
+/* Size of the stack when we started.  */
+
+#ifdef SET_STACK_SIZE
+struct rlimit stack_limit;
+#endif
+
+
 /* Number of job slots (commands that can be run at once).  */
 
 unsigned int job_slots = 1;
@@ -919,11 +918,15 @@
     struct rlimit rlim;
 
     /* Set the stack limit huge so that alloca does not fail.  */
-    if (getrlimit (RLIMIT_STACK, &rlim) == 0)
+    if (getrlimit (RLIMIT_STACK, &rlim) == 0
+        && rlim.rlim_cur > 0 && rlim.rlim_cur < rlim.rlim_max)
       {
+        stack_limit = rlim;
         rlim.rlim_cur = rlim.rlim_max;
         setrlimit (RLIMIT_STACK, &rlim);
       }
+    else
+      stack_limit.rlim_cur = 0;
   }
 #endif
 
diff -Naur make-3.81.orig/make.h make-3.81/make.h
--- make-3.81.orig/make.h	2006-02-15 23:54:43.000000000 +0000
+++ make-3.81/make.h	2010-02-24 09:46:47.000000000 +0000
@@ -378,6 +378,14 @@
 extern int unixy_shell;
 #endif  /* WINDOWS32 */
 
+#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
+# define SET_STACK_SIZE
+#endif
+#ifdef SET_STACK_SIZE
+# include <sys/resource.h>
+struct rlimit stack_limit;
+#endif
+
 struct floc
   {
     const char *filenm;
