Module Name:    src
Committed By:   rillig
Date:           Sat Aug 29 08:59:08 UTC 2020

Modified Files:
        src/usr.bin/make: main.c

Log Message:
make(1): fix null pointer dereference when sys.mk is not found

This is quite hard to trigger in a real-life scenario since it requires
precise timing.

Instead, I created /tmp/sys.mk and ran "./make -m /tmp -f /dev/null" in
the debugger, after setting a breakpoint in this line:

ln = Lst_Find(sysMkPath, ReadMakefile, NULL);

Once this line was reached, I removed /tmp/sys.mk to make ReadMakefile
fail.  Just adding a few parse errors won't help since ReadMakefile only
fails if the file cannot be found.


To generate a diff of this commit:
cvs rdiff -u -r1.323 -r1.324 src/usr.bin/make/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.323 src/usr.bin/make/main.c:1.324
--- src/usr.bin/make/main.c:1.323	Sat Aug 29 07:52:55 2020
+++ src/usr.bin/make/main.c	Sat Aug 29 08:59:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.323 2020/08/29 07:52:55 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.324 2020/08/29 08:59:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.323 2020/08/29 07:52:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.324 2020/08/29 08:59:08 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.323 2020/08/29 07:52:55 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.324 2020/08/29 08:59:08 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1329,7 +1329,7 @@ main(int argc, char **argv)
 		ln = Lst_Find(sysMkPath, ReadMakefile, NULL);
 		if (ln == NULL)
 			Fatal("%s: cannot open %s.", progname,
-			    (char *)Lst_Datum(ln));
+			    (char *)Lst_Datum(Lst_First(sysMkPath)));
 	}
 
 	if (!Lst_IsEmpty(makefiles)) {

Reply via email to