Module Name:    src
Committed By:   rillig
Date:           Mon Apr  1 12:26:02 UTC 2024

Modified Files:
        src/usr.bin/make: parse.c
        src/usr.bin/make/unit-tests: directive-for-null.exp
            directive-for-null.mk opt-file.exp opt-file.mk

Log Message:
make: exit immediately after reading a null byte from a makefile

The chance of other garbage bytes in such a file is just too high.


To generate a diff of this commit:
cvs rdiff -u -r1.717 -r1.718 src/usr.bin/make/parse.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-for-null.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-for-null.mk
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/opt-file.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/opt-file.mk

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/parse.c
diff -u src/usr.bin/make/parse.c:1.717 src/usr.bin/make/parse.c:1.718
--- src/usr.bin/make/parse.c:1.717	Wed Feb  7 06:43:02 2024
+++ src/usr.bin/make/parse.c	Mon Apr  1 12:26:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.717 2024/02/07 06:43:02 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.718 2024/04/01 12:26:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.717 2024/02/07 06:43:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.718 2024/04/01 12:26:02 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -2368,7 +2368,7 @@ ParseRawLine(IncludedFile *curFile, char
 		ch = *p;
 		if (ch == '\0' || (ch == '\\' && p[1] == '\0')) {
 			Parse_Error(PARSE_FATAL, "Zero byte read from file");
-			return PRLR_ERROR;
+			exit(2);
 		}
 
 		/* Treat next character after '\' as literal. */

Index: src/usr.bin/make/unit-tests/directive-for-null.exp
diff -u src/usr.bin/make/unit-tests/directive-for-null.exp:1.2 src/usr.bin/make/unit-tests/directive-for-null.exp:1.3
--- src/usr.bin/make/unit-tests/directive-for-null.exp:1.2	Thu Dec  9 20:13:10 2021
+++ src/usr.bin/make/unit-tests/directive-for-null.exp	Mon Apr  1 12:26:02 2024
@@ -1,9 +1,5 @@
 make: "(stdin)" line 2: Zero byte read from file
-make: "(stdin)" line 2: Unexpected end of file in .for loop
-make: "(stdin)" line 3: Zero byte read from file
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-*** Error code 1 (continuing)
+*** Error code 2 (continuing)
 
 Stop.
 make: stopped in unit-tests

Index: src/usr.bin/make/unit-tests/directive-for-null.mk
diff -u src/usr.bin/make/unit-tests/directive-for-null.mk:1.3 src/usr.bin/make/unit-tests/directive-for-null.mk:1.4
--- src/usr.bin/make/unit-tests/directive-for-null.mk:1.3	Sun Jun 12 15:03:27 2022
+++ src/usr.bin/make/unit-tests/directive-for-null.mk	Mon Apr  1 12:26:02 2024
@@ -1,18 +1,8 @@
-# $NetBSD: directive-for-null.mk,v 1.3 2022/06/12 15:03:27 rillig Exp $
+# $NetBSD: directive-for-null.mk,v 1.4 2024/04/01 12:26:02 rillig Exp $
 #
 # Test for parsing a .for loop that accidentally contains a null byte.
 #
-# As of 2020-12-19, there are 3 error messages:
-#
-#	make: "(stdin)" line 2: Zero byte read from file
-#	make: "(stdin)" line 2: Unexpected end of file in for loop.
-#	make: "(stdin)" line 3: Zero byte read from file
-#
-# The one about "end of file" might be misleading but is due to the
-# implementation.  On both errors and EOF, ParseRawLine returns NULL.
-#
-# The one about the "zero byte" in line 3 is surprising since the only
-# line that contains a null byte is line 2.
+# expect: make: "(stdin)" line 2: Zero byte read from file
 
 all: .PHONY
 	@printf '%s\n' \

Index: src/usr.bin/make/unit-tests/opt-file.exp
diff -u src/usr.bin/make/unit-tests/opt-file.exp:1.7 src/usr.bin/make/unit-tests/opt-file.exp:1.8
--- src/usr.bin/make/unit-tests/opt-file.exp:1.7	Tue Dec 22 08:51:30 2020
+++ src/usr.bin/make/unit-tests/opt-file.exp	Mon Apr  1 12:26:02 2024
@@ -2,9 +2,7 @@ value
 value
 line-with-trailing-whitespace
 make: "(stdin)" line 1: Zero byte read from file
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-*** Error code 1 (continuing)
+*** Error code 2 (continuing)
 `all' not remade because of errors.
 
 Stop.

Index: src/usr.bin/make/unit-tests/opt-file.mk
diff -u src/usr.bin/make/unit-tests/opt-file.mk:1.15 src/usr.bin/make/unit-tests/opt-file.mk:1.16
--- src/usr.bin/make/unit-tests/opt-file.mk:1.15	Sat Mar 26 13:32:31 2022
+++ src/usr.bin/make/unit-tests/opt-file.mk	Mon Apr  1 12:26:02 2024
@@ -1,4 +1,4 @@
-# $NetBSD: opt-file.mk,v 1.15 2022/03/26 13:32:31 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.16 2024/04/01 12:26:02 rillig Exp $
 #
 # Tests for the -f command line option, which adds a makefile to the list of
 # files that are parsed.
@@ -79,7 +79,7 @@ line-with-trailing-whitespace: .PHONY
 #	exit status 0
 #
 #	2008 to 2010:
-#	make: "zero-byte.in" line 1: Zero byte read from file
+#	make: "(stdin)" line 1: Zero byte read from file
 #	make: Fatal errors encountered -- cannot continue
 #
 #	make: stopped in .
@@ -92,14 +92,18 @@ line-with-trailing-whitespace: .PHONY
 #	exit status 2
 #
 #	2014 to 2020-12-06:
-#	make: "zero-byte.in" line 1: warning: Zero byte read from file, skipping rest of line.
+#	make: "(stdin)" line 1: warning: Zero byte read from file, skipping rest of line.
 #	exit status 0
 #
 #	Since 2020-12-07:
-#	make: "zero-byte.in" line 1: Zero byte read from file
+#	make: "(stdin)" line 1: Zero byte read from file
 #	make: Fatal errors encountered -- cannot continue
 #	make: stopped in .
 #	exit status 1
+#
+#	Since 2024-04-01:
+#	make: "(stdin)" line 1: Zero byte read from file
+#	*** Error code 2 (continuing)
 file-containing-null-byte: .PHONY
 	@printf '%s\n' 'VAR=value' 'VAR2=VALUE2' \
 	| tr 'l' '\0' \

Reply via email to