Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): error out on null bytes in makefiles
details: https://anonhg.NetBSD.org/src/rev/f91c235ba459
branches: trunk
changeset: 1016940:f91c235ba459
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Dec 06 20:33:44 2020 +0000
description:
make(1): error out on null bytes in makefiles
Makefiles are text files, they must not contain null bytes.
The previous code in this area was rotten anyway. It assumed that
buf_end could be NULL even if buf_ptr was a valid pointer, which is no
longer true, probably since a few years already.
Continuing parsing after a null byte does not make sense. If there's a
null byte in a text file, that file is corrupted, and parsing it leads
to unintended effects easily. Therefore the only sensible action is to
stop parsing immediately.
The check whether cf->readMore could be null was outdated as well, which
previously made the fatal error impossible to reach. Because of the
missing unit tests, nobody noticed this though.
The "exit status 0" in opt-file.exp is worring but that's due to another
bug and will be fixed in a follow-up commit.
diffstat:
usr.bin/make/parse.c | 38 +++++------------------------------
usr.bin/make/unit-tests/opt-file.exp | 8 ++++--
usr.bin/make/unit-tests/opt-file.mk | 12 +++++++---
3 files changed, 19 insertions(+), 39 deletions(-)
diffs (110 lines):
diff -r dbc284675a9b -r f91c235ba459 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sun Dec 06 20:09:01 2020 +0000
+++ b/usr.bin/make/parse.c Sun Dec 06 20:33:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.471 2020/12/06 20:09:01 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.472 2020/12/06 20:33:44 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.471 2020/12/06 20:09:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.472 2020/12/06 20:33:44 rillig Exp $");
/* types and constants */
@@ -2687,41 +2687,15 @@
escaped = NULL;
comment = NULL;
for (;;) {
- /* XXX: can buf_end ever be null? */
- if (cf->buf_end != NULL && ptr == cf->buf_end) {
+ if (ptr == cf->buf_end) {
/* end of buffer */
ch = '\0';
break;
}
ch = *ptr;
- if (ch == '\0' || (ch == '\\' && ptr[1] == '\0')) {
-
- /* XXX: can buf_end ever be null? */
- if (cf->buf_end == NULL)
- /* End of string (aka for loop) data */
- break;
-
- /* see if there is more we can parse */
- while (ptr++ < cf->buf_end) {
- if ((ch = *ptr) == '\n') {
- if (ptr > line &&
- ptr[-1] == '\\')
- continue;
- Parse_Error(PARSE_WARNING,
- "Zero byte read from file, "
- "skipping rest of line.");
- break;
- }
- }
- /* XXX: Can cf->readMore ever be NULL? */
- if (cf->readMore != NULL) {
- /*
- * End of this buffer; return EOF and
- * outer logic will get the next one.
- * (eww)
- */
- break;
- }
+ if (ch == '\0' ||
+ (ch == '\\' && ptr + 1 < cf->buf_end &&
+ ptr[1] == '\0')) {
Parse_Error(PARSE_FATAL,
"Zero byte read from file");
return NULL;
diff -r dbc284675a9b -r f91c235ba459 usr.bin/make/unit-tests/opt-file.exp
--- a/usr.bin/make/unit-tests/opt-file.exp Sun Dec 06 20:09:01 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-file.exp Sun Dec 06 20:33:44 2020 +0000
@@ -1,5 +1,7 @@
value
-make: "(stdin)" line 1: warning: Zero byte read from file, skipping rest of line.
-va
-VALUE2
+make: "(stdin)" line 1: Zero byte read from file
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+*** Error code 1 (continuing)
+`all' not remade because of errors.
exit status 0
diff -r dbc284675a9b -r f91c235ba459 usr.bin/make/unit-tests/opt-file.mk
--- a/usr.bin/make/unit-tests/opt-file.mk Sun Dec 06 20:09:01 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-file.mk Sun Dec 06 20:33:44 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: opt-file.mk,v 1.5 2020/12/06 20:07:25 rillig Exp $
+# $NetBSD: opt-file.mk,v 1.6 2020/12/06 20:33:44 rillig Exp $
#
# Tests for the -f command line option.
@@ -49,15 +49,19 @@
# make: stopped in .
# exit status 2
#
-# 2014:
+# 2014 to 2020-12-06:
# make: "zero-byte.in" line 1: warning: Zero byte read from file, skipping rest of line.
# exit status 0
#
-# XXX: It would be safer to just quit parsing in such a situation.
+# Since 2020-12-07:
+# make: "zero-byte.in" line 1: Zero byte read from file
+# make: Fatal errors encountered -- cannot continue
+# make: stopped in .
+# exit status 1
file-containing-null-byte: .PHONY
@printf '%s\n' 'VAR=value' 'VAR2=VALUE2' \
| tr 'l' '\0' \
| ${MAKE} -r -f - -v VAR -v VAR2
all:
- @:;
+ : Making ${.TARGET}
Home |
Main Index |
Thread Index |
Old Index