usr.bin/make Bug fixes from FreeBSD

Max Okumoto okumoto at ucsd.edu
Wed Nov 24 03:35:59 PST 2004


PatchSet 299 Date: 2002/11/08 16:59:11 Author: jmallett
        o Convert some broken cases where Error is called, but we
          try to continue, to Fatal errors, because the logic that
          we use to try to continue is far too broken, and makes
          things look and act weird, because we end up pointing
          past the end of a buffer boundry into freed memory in the
          caller, as we don't come close to setting the lengthPtr
          to a sane value.
          (This only changes failure cases which would have died
          horrid deaths to explicit clean death failure cases.)
PatchSet 312 Date: 2003/04/04 04:17:14 Author: imp
        o No need to check to see if we're running a version of
          FreeBSD 3.0 current or newer anymore.
PatchSet 317 Date: 2003/09/07 03:16:10 Author: imp
        o Keep up with minor changes to NetBSD.  Consider a variable
          empty when not define.
PatchSet 318 Date: 2003/09/08 09:23:29 Author: ru
        o Command line variables take precedence over global
          variables.  Make this true in the .for loops too.  The
          following fragment,
          FOO=  foo bar

          all:
          .for f in ${FOO}
                @echo ${f}
          .endfor
          when run as "make FOO=xxx" should print "xxx".  (OpenBSD
          had this bug fixed for some time.)
PatchSet 319 Date: 2003/09/14 13:31:33 Author: ru
        - Cut out the code that caches the "." directory out of
 	  Dir_Init() into a separate function, Dir_InitDot().
        - Postpone the current and object directories detection (and
	  caching of the "." directory) until after all command line
          arguments are parsed.  This makes the -C option DTRT.
        PR:             bin/47149
---------------------
PatchSet 299
Date: 2002/11/08 16:59:11
Author: jmallett
Log:
Convert some broken cases where Error is called, but we try to continue,
to Fatal errors, because the logic that we use to try to continue is far
too broken, and makes things look and act weird, because we end up pointing
past the end of a buffer boundry into freed memory in the caller, as we
don't come close to setting the lengthPtr to a sane value.

Reviewed by:	make@

(This only changes failure cases which would have died horrid deaths to
 explicit clean death failure cases.)

Members: 
	var.c:1.39->1.40 

Index: var.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/var.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- var.c	28 Oct 2002 23:33:57 -0000	1.39
+++ var.c	8 Nov 2002 16:59:11 -0000	1.40
@@ -1268,17 +1268,11 @@
 
 		    /*
 		     * If lhs didn't end with the delimiter, complain and
-		     * return NULL
+		     * exit.
 		     */
 		    if (*cp != del) {
-			*lengthPtr = cp - start + 1;
-			if (*freePtr) {
-			    free(str);
-			}
-			Buf_Destroy(buf, TRUE);
-			Error("Unclosed substitution for %s (%c missing)",
+			Fatal("Unclosed substitution for %s (%c missing)",
 			      v->name, del);
-			return (var_Error);
 		    }
 
 		    /*
@@ -1336,14 +1330,8 @@
 		     * If didn't end in delimiter character, complain
 		     */
 		    if (*cp != del) {
-			*lengthPtr = cp - start + 1;
-			if (*freePtr) {
-			    free(str);
-			}
-			Buf_Destroy(buf, TRUE);
-			Error("Unclosed substitution for %s (%c missing)",
+			Fatal("Unclosed substitution for %s (%c missing)",
 			      v->name, del);
-			return (var_Error);
 		    }
 
 		    pattern.rhs = (char *)Buf_GetAll(buf, &pattern.rightLen);
@@ -1390,7 +1378,7 @@
 			if (*freePtr)
 			    free(str);
 			if (delim != '\0')
-			    Error("Unclosed substitution for %s (%c missing)",
+			    Fatal("Unclosed substitution for %s (%c missing)",
 				  v->name, delim);
 			return (var_Error);
 		    }
@@ -1404,7 +1392,7 @@
 			if (*freePtr)
 			    free(str);
 			if (delim != '\0')
-			    Error("Unclosed substitution for %s (%c missing)",
+			    Fatal("Unclosed substitution for %s (%c missing)",
 				  v->name, delim);
 			return (var_Error);
 		    }
---------------------
PatchSet 312
Date: 2003/04/04 04:17:14
Author: imp
Log:
No need to check to see if we're running a version of FreeBSD 3.0 current or
newer anymore.

Members: 
	main.c:1.81->1.82 

Index: main.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/main.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- main.c	17 Dec 2002 04:26:22 -0000	1.81
+++ main.c	4 Apr 2003 04:17:14 -0000	1.82
@@ -497,7 +497,6 @@
 	if (stat(curdir, &sa) == -1)
 	    err(2, "%s", curdir);
 
-#if defined(__i386__) && defined(__DragonFly_version)
 	/*
 	 * PC-98 kernel sets the `i386' string to the utsname.machine and
 	 * it cannot be distinguished from IBM-PC by uname(3).  Therefore,
@@ -518,7 +516,6 @@
 				machine = "pc98";
 		}
 	}
-#endif
 
 	/*
 	 * Get the name of this type of MACHINE from utsname

--- dfly-src/make/main.c	Wed Nov 17 03:40:52 2004
+++ fbsd-src/make/main.c	Wed Nov 17 03:40:50 2004
@@ -487,7 +487,9 @@
 	 * it cannot be distinguished from IBM-PC by uname(3).  Therefore,
 	 * we check machine.ispc98 and adjust the machine variable before
 	 * using usname(3) below.
-	 * NOTE: machdep.ispc98 was defined on 1998/8/31.
+	 * NOTE: machdep.ispc98 was defined on 1998/8/31. At that time,
+	 * __FreeBSD_version was defined as 300003. So, this check can
+	 * safely be done with any kernel with version > 300003.
 	 */
 	if (!machine) {
 		int	ispc98;
---------------------
PatchSet 317
Date: 2003/09/07 03:16:10
Author: imp
Log:
Keep up with minor changes to NetBSD.  Consider a variable empty when
not define.

Obtained From: NetBSD (rev 1.18; sjg)

Members: 
	cond.c:1.26->1.27 

Index: cond.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/cond.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- cond.c	4 Jul 2003 13:33:48 -0000	1.26
+++ cond.c	7 Sep 2003 02:16:10 -0000	1.27
@@ -803,7 +803,7 @@
 
 		    if (condExpr[arglen] != '\0') {
 			val = Var_Parse(&condExpr[arglen - 1], VAR_CMD,
-					doEval, &length, &doFree);
+					FALSE, &length, &doFree);
 			if (val == var_Error) {
 			    t = Err;
 			} else {
---------------------
PatchSet 318
Date: 2003/09/08 09:23:29
Author: ru
Log:
Command line variables take precedence over global variables.
Make this true in the .for loops too.  The following fragment,

	FOO=	foo bar

	all:
	.for f in ${FOO}
		@echo ${f}
	.endfor

when run as "make FOO=xxx" should print "xxx".  (OpenBSD had
this bug fixed for some time.)

Members: 
	for.c:1.19->1.20 

Index: for.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/for.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- for.c	9 Oct 2002 03:42:10 -0000	1.19
+++ for.c	8 Sep 2003 08:23:29 -0000	1.20
@@ -172,7 +172,7 @@
 	 */
 	forLst = Lst_Init(FALSE);
 	buf = Buf_Init(0);
-	sub = Var_Subst(NULL, ptr, VAR_GLOBAL, FALSE);
+	sub = Var_Subst(NULL, ptr, VAR_CMD, FALSE);
 
 #define	ADDWORD() \
 	Buf_AddBytes(buf, ptr - wrd, (Byte *) wrd), \
---------------------
PatchSet 319
Date: 2003/09/14 13:31:33
Author: ru
Log:
- Cut out the code that caches the "." directory out of Dir_Init()
  into a separate function, Dir_InitDot().

- Postpone the current and object directories detection (and caching
  of the "." directory) until after all command line arguments are
  parsed.  This makes the -C option DTRT.

PR:		bin/47149

Members: 
	dir.c:1.30->1.31 
	dir.h:1.10->1.11 
	main.c:1.83->1.84 
	make.1:1.62->1.63 

Index: dir.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/dir.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- dir.c	9 Oct 2002 03:42:10 -0000	1.30
+++ dir.c	14 Sep 2003 12:31:33 -0000	1.31
@@ -205,7 +205,7 @@
  *	none
  *
  * Side Effects:
- *	some directories may be opened.
+ *	none
  *-----------------------------------------------------------------------
  */
 void
@@ -214,15 +214,25 @@
     dirSearchPath = Lst_Init (FALSE);
     openDirectories = Lst_Init (FALSE);
     Hash_InitTable(&mtimes, 0);
+}
 
-    /*
-     * Since the Path structure is placed on both openDirectories and
-     * the path we give Dir_AddDir (which in this case is openDirectories),
-     * we need to remove "." from openDirectories and what better time to
-     * do it than when we have to fetch the thing anyway?
-     */
+/*-
+ *-----------------------------------------------------------------------
+ * Dir_InitDot --
+ *	initialize the "." directory
+ *
+ * Results:
+ *	none
+ *
+ * Side Effects:
+ *	some directories may be opened.
+ *-----------------------------------------------------------------------
+ */
+void
+Dir_InitDot (void)
+{
     Dir_AddDir (openDirectories, ".");
-    dot = (Path *) Lst_DeQueue (openDirectories);
+    dot = (Path *)Lst_Datum(Lst_Last(openDirectories));
     if (dot == (Path *) NULL)
 	err(1, "cannot open current directory");
 
@@ -1031,7 +1041,8 @@
 	    }
 	    (void) closedir (d);
 	    (void)Lst_AtEnd (openDirectories, (void *)p);
-	    (void)Lst_AtEnd (path, (void *)p);
+	    if (path != openDirectories)
+		(void)Lst_AtEnd (path, (void *)p);
 	}
 	DEBUGF(DIR, ("done\n"));
     }
Index: dir.h
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/dir.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- dir.h	13 Apr 2002 10:57:56 -0000	1.10
+++ dir.h	14 Sep 2003 12:31:33 -0000	1.11
@@ -55,6 +55,7 @@
 } Path;
 
 void Dir_Init(void);
+void Dir_InitDot(void);
 void Dir_End(void);
 Boolean Dir_HasWildcards(char *);
 void Dir_Expand(char *, Lst, Lst);
Index: main.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/main.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- main.c	15 Apr 2003 14:27:21 -0000	1.83
+++ main.c	14 Sep 2003 12:31:33 -0000	1.84
@@ -485,17 +485,6 @@
 		}
 	}
 #endif
-	/*
-	 * Find where we are...
-	 * All this code is so that we know where we are when we start up
-	 * on a different machine with pmake.
-	 */
-	curdir = cdpath;
-	if (getcwd(curdir, MAXPATHLEN) == NULL)
-		err(2, NULL);
-
-	if (stat(curdir, &sa) == -1)
-	    err(2, "%s", curdir);
 
 	/*
 	 * PC-98 kernel sets the `i386' string to the utsname.machine and
@@ -557,48 +546,6 @@
 		else
 			machine_cpu = "unknown";
 	}
-	
-	/*
-	 * The object directory location is determined using the
-	 * following order of preference:
-	 *
-	 *	1. MAKEOBJDIRPREFIX`cwd`
-	 *	2. MAKEOBJDIR
-	 *	3. _PATH_OBJDIR.${MACHINE}
-	 *	4. _PATH_OBJDIR
-	 *	5. _PATH_OBJDIRPREFIX`cwd`
-	 *
-	 * If one of the first two fails, use the current directory.
-	 * If the remaining three all fail, use the current directory.
-	 *
-	 * Once things are initted,
-	 * have to add the original directory to the search path,
-	 * and modify the paths for the Makefiles apropriately.  The
-	 * current directory is also placed as a variable for make scripts.
-	 */
-	if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) {
-		if (!(path = getenv("MAKEOBJDIR"))) {
-			path = _PATH_OBJDIR;
-			pathp = _PATH_OBJDIRPREFIX;
-			(void) snprintf(mdpath, MAXPATHLEN, "%s.%s",
-					path, machine);
-			if (!(objdir = chdir_verify_path(mdpath, obpath)))
-				if (!(objdir=chdir_verify_path(path, obpath))) {
-					(void) snprintf(mdpath, MAXPATHLEN,
-							"%s%s", pathp, curdir);
-					if (!(objdir=chdir_verify_path(mdpath,
-								       obpath)))
-						objdir = curdir;
-				}
-		}
-		else if (!(objdir = chdir_verify_path(path, obpath)))
-			objdir = curdir;
-	}
-	else {
-		(void) snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
-		if (!(objdir = chdir_verify_path(mdpath, obpath)))
-			objdir = curdir;
-	}
 
 	create = Lst_Init(FALSE);
 	makefiles = Lst_Init(FALSE);
@@ -639,11 +586,6 @@
 	Var_Init();		/* As well as the lists of variables for
 				 * parsing arguments */
         str_init();
-	if (objdir != curdir)
-		Dir_AddDir(dirSearchPath, curdir);
-	Var_Set(".DIRECTIVE_MAKEENV", "YES", VAR_GLOBAL);
-	Var_Set(".CURDIR", curdir, VAR_GLOBAL);
-	Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
 
 	/*
 	 * Initialize various variables.
@@ -672,6 +615,66 @@
 #endif
 
 	MainParseArgs(argc, argv);
+
+	/*
+	 * Find where we are...
+	 * All this code is so that we know where we are when we start up
+	 * on a different machine with pmake.
+	 */
+	curdir = cdpath;
+	if (getcwd(curdir, MAXPATHLEN) == NULL)
+		err(2, NULL);
+
+	if (stat(curdir, &sa) == -1)
+	    err(2, "%s", curdir);
+
+	/*
+	 * The object directory location is determined using the
+	 * following order of preference:
+	 *
+	 *	1. MAKEOBJDIRPREFIX`cwd`
+	 *	2. MAKEOBJDIR
+	 *	3. _PATH_OBJDIR.${MACHINE}
+	 *	4. _PATH_OBJDIR
+	 *	5. _PATH_OBJDIRPREFIX`cwd`
+	 *
+	 * If one of the first two fails, use the current directory.
+	 * If the remaining three all fail, use the current directory.
+	 *
+	 * Once things are initted,
+	 * have to add the original directory to the search path,
+	 * and modify the paths for the Makefiles apropriately.  The
+	 * current directory is also placed as a variable for make scripts.
+	 */
+	if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) {
+		if (!(path = getenv("MAKEOBJDIR"))) {
+			path = _PATH_OBJDIR;
+			pathp = _PATH_OBJDIRPREFIX;
+			(void) snprintf(mdpath, MAXPATHLEN, "%s.%s",
+					path, machine);
+			if (!(objdir = chdir_verify_path(mdpath, obpath)))
+				if (!(objdir=chdir_verify_path(path, obpath))) {
+					(void) snprintf(mdpath, MAXPATHLEN,
+							"%s%s", pathp, curdir);
+					if (!(objdir=chdir_verify_path(mdpath,
+								       obpath)))
+						objdir = curdir;
+				}
+		}
+		else if (!(objdir = chdir_verify_path(path, obpath)))
+			objdir = curdir;
+	}
+	else {
+		(void) snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
+		if (!(objdir = chdir_verify_path(mdpath, obpath)))
+			objdir = curdir;
+	}
+	Dir_InitDot();		/* Initialize the "." directory */
+	if (objdir != curdir)
+		Dir_AddDir(dirSearchPath, curdir);
+	Var_Set(".DIRECTIVE_MAKEENV", "YES", VAR_GLOBAL);
+	Var_Set(".CURDIR", curdir, VAR_GLOBAL);
+	Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
 
 	/*
 	 * Be compatible if user did not specify -j and did not explicitly
Index: make.1
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/make.1,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- make.1	23 Dec 2002 16:04:51 -0000	1.62
+++ make.1	14 Sep 2003 12:31:33 -0000	1.63
@@ -92,7 +92,13 @@
 .It Fl C Ar directory
 Change to
 .Ar directory
-while running.
+before reading the makefiles or doing anything else.
+If multiple
+.Fl C
+options are specified, each is interpreted relative to the previous one:
+.Fl C Pa / Fl C Pa etc
+is equivalent to
+.Fl C Pa /etc .
 .It Fl D Ar variable
 Define
 .Ar variable




More information about the Submit mailing list