From 6d6b143d8f4e92c39f6534f7f0362ab471ac2fe0 Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 18 Apr 2020 12:21:10 +0000 Subject: mk/subst.mk: avoid undefined behavior in regular expressions https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html says in section 9.3.2 BRE Ordinary Characters that only very few characters may be preceded with a backslash. As a side effect, this change allows parentheses in the variable names listed in SUBST_VARS (even if that will never happen in practice). The reason that the regression test had not replaced VAR.[] before was simply that this variable had not been listed in SUBST_VARS. --- mk/subst.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mk/subst.mk') diff --git a/mk/subst.mk b/mk/subst.mk index 099a130a0ba..cd9b769748a 100644 --- a/mk/subst.mk +++ b/mk/subst.mk @@ -1,4 +1,4 @@ -# $NetBSD: subst.mk,v 1.76 2020/04/18 11:42:34 rillig Exp $ +# $NetBSD: subst.mk,v 1.77 2020/04/18 12:21:10 rillig Exp $ # # The subst framework replaces text in one or more files in the WRKSRC # directory. Packages can define several ``classes'' of replacements. @@ -128,7 +128,7 @@ SUBST_FILTER_CMD.${class}?= LC_ALL=C ${SED} ${SUBST_SED.${class}} SUBST_VARS.${class}?= # none SUBST_MESSAGE.${class}?= Substituting "${class}" in ${SUBST_FILES.${class}} . for v in ${SUBST_VARS.${class}} -SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[^A-Za-z0-9_]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g +SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[.[\\*^${$}]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g . endfor . if ${SUBST_SHOW_DIFF.${class}:U${SUBST_SHOW_DIFF}:tl} == yes _SUBST_KEEP.${class}?= LC_ALL=C ${DIFF} -u "$$file" "$$tmpfile" || true -- cgit v1.2.3