Module Name: src
Committed By: rillig
Date: Thu Aug 17 19:06:51 UTC 2023
Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-mtime.exp varmod-mtime.mk
Log Message:
make: be strict when parsing the argument of the ':mtime' modifier
To generate a diff of this commit:
cvs rdiff -u -r1.1060 -r1.1061 src/usr.bin/make/var.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-mtime.exp \
src/usr.bin/make/unit-tests/varmod-mtime.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/var.c
diff -u src/usr.bin/make/var.c:1.1060 src/usr.bin/make/var.c:1.1061
--- src/usr.bin/make/var.c:1.1060 Thu Aug 17 18:52:51 2023
+++ src/usr.bin/make/var.c Thu Aug 17 19:06:51 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1060 2023/08/17 18:52:51 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1061 2023/08/17 19:06:51 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1060 2023/08/17 18:52:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1061 2023/08/17 19:06:51 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -2885,11 +2885,16 @@ ApplyModifier_Mtime(const char **pp, Mod
if (args.use_fallback) {
p++;
if (TryParseTime(&p, &args.fallback)) {
- } else if (strncmp(p, "error", 5) == 0) {
+ } else if (strncmp(p, "error", 5) == 0
+ && IsDelimiter(p[5], ch)) {
p += 5;
args.error = true;
- } else
- return AMR_BAD;
+ } else {
+ Parse_Error(PARSE_FATAL,
+ "Invalid argument '%.*s' for modifier ':mtime'",
+ (int)strcspn(p, ":{}()"), p);
+ return AMR_CLEANUP;
+ }
*pp = p;
}
if (!ModChain_ShouldEval(ch))
Index: src/usr.bin/make/unit-tests/varmod-mtime.exp
diff -u src/usr.bin/make/unit-tests/varmod-mtime.exp:1.2 src/usr.bin/make/unit-tests/varmod-mtime.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-mtime.exp:1.2 Thu Aug 17 18:48:32 2023
+++ src/usr.bin/make/unit-tests/varmod-mtime.exp Thu Aug 17 19:06:51 2023
@@ -1,7 +1,7 @@
make: "varmod-mtime.mk" line 58: Cannot determine mtime for 'no/such/file1': <ENOENT>
make: "varmod-mtime.mk" line 58: Cannot determine mtime for 'no/such/file2': <ENOENT>
make: "varmod-mtime.mk" line 58: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error})
-make: "varmod-mtime.mk" line 69: Unknown modifier "handler-no"
+make: "varmod-mtime.mk" line 69: Invalid argument 'errorhandler-no' for modifier ':mtime'
make: "varmod-mtime.mk" line 69: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
Index: src/usr.bin/make/unit-tests/varmod-mtime.mk
diff -u src/usr.bin/make/unit-tests/varmod-mtime.mk:1.2 src/usr.bin/make/unit-tests/varmod-mtime.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-mtime.mk:1.2 Thu Aug 17 18:48:32 2023
+++ src/usr.bin/make/unit-tests/varmod-mtime.mk Thu Aug 17 19:06:51 2023
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-mtime.mk,v 1.2 2023/08/17 18:48:32 rillig Exp $
+# $NetBSD: varmod-mtime.mk,v 1.3 2023/08/17 19:06:51 rillig Exp $
#
# Tests for the ':mtime' variable modifier, which maps each word of the
# expression to that file's modification time.
@@ -62,9 +62,9 @@ _!= rm -f ${COOKIE}
.endif
-# TODO: Only the word 'error' is a special argument to the ':mtime' modifier,
-# all other words should result in a parse error.
-# expect+2: Unknown modifier "handler-no"
+# Only the word 'error' is a special argument to the ':mtime' modifier, all
+# other words result in a parse error.
+# expect+2: Invalid argument 'errorhandler-no' for modifier ':mtime'
# expect+1: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0)
.if ${MAKEFILE:mtime=errorhandler-no} > 0
.else