summaryrefslogtreecommitdiff
path: root/usr.bin/make/unit-tests/varparse-errors.mk
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2022-08-24 22:09:40 +0000
committerrillig <rillig@NetBSD.org>2022-08-24 22:09:40 +0000
commit396ab02ad48f5c75849c1efb5cd16c2195542e17 (patch)
tree3803bb501754a62146183ad28a78aa878e146db1 /usr.bin/make/unit-tests/varparse-errors.mk
parent757dc0dadcc1494a82dcc07a0bc803b9420c698c (diff)
make: prevent future out-of-bounds errors when parsing expressions
A modifier in an expression ends not only at the next ':' or at the closing '}' or ')', but also at the end of the string. Previously, testing for the end of the string had been done separately, which was error-prone since 2006-05-11, when indirect modifiers were introduced. Since then, it was possible that the string terminator '\0' was accidentally skipped in cases where the loop condition only tested for the ending character. When parsing indirect modifiers, the ending character is indeed '\0', but when parsing direct modifiers, it is '}' or ')'. A welcome side effect is that in the case of unclosed expressions such as '${VAR:Modifier', the amount of error messages is reduced from 2 or 3 to only 1. The removed error messages were wrong and thus confusing anyway.
Diffstat (limited to 'usr.bin/make/unit-tests/varparse-errors.mk')
-rw-r--r--usr.bin/make/unit-tests/varparse-errors.mk20
1 files changed, 5 insertions, 15 deletions
diff --git a/usr.bin/make/unit-tests/varparse-errors.mk b/usr.bin/make/unit-tests/varparse-errors.mk
index 69fb65322a3..9174d264db0 100644
--- a/usr.bin/make/unit-tests/varparse-errors.mk
+++ b/usr.bin/make/unit-tests/varparse-errors.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varparse-errors.mk,v 1.6 2022/08/24 21:38:06 rillig Exp $
+# $NetBSD: varparse-errors.mk,v 1.7 2022/08/24 22:09:41 rillig Exp $
# Tests for parsing and evaluating all kinds of variable expressions.
#
@@ -68,31 +68,21 @@ IND= ${:OX}
_:= ${:U:OX:U${IND}} ${:U:OX:U${IND}}
#.MAKEFLAGS: -d0
-# expect+1: Unknown modifier "Q"
+
+# Before var.c 1.032 from 2022-08-24, make complained about 'Unknown modifier'
+# or 'Bad modifier' when in fact the modifier was entirely correct, it was
+# just not delimited by either ':' or '}' but instead by '\0'.
UNCLOSED:= ${:U:Q
-# expect+1: Unknown modifier "sh"
UNCLOSED:= ${:U:sh
-# expect: make: Bad modifier ":tA" for variable ""
UNCLOSED:= ${:U:tA
-# expect: make: Bad modifier ":tsX" for variable ""
UNCLOSED:= ${:U:tsX
-# expect: make: Bad modifier ":ts" for variable ""
UNCLOSED:= ${:U:ts
-# expect: make: Bad modifier ":ts\040" for variable ""
UNCLOSED:= ${:U:ts\040
-# expect+1: Unknown modifier "u"
UNCLOSED:= ${:U:u
-# expect+1: Unknown modifier "H"
UNCLOSED:= ${:U:H
-# expect: make: Bad modifier ":[1]" for variable ""
UNCLOSED:= ${:U:[1]
-# expect+1: Unknown modifier "hash"
UNCLOSED:= ${:U:hash
-# expect+1: Unknown modifier "range"
UNCLOSED:= ${:U:range
-# expect+1: Unknown modifier "_"
UNCLOSED:= ${:U:_
-# expect+1: Unknown modifier "gmtime"
UNCLOSED:= ${:U:gmtime
-# expect+1: Unknown modifier "localtime"
UNCLOSED:= ${:U:localtime