pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sat Apr 18 12:21:11 UTC 2020

Modified Files:
        pkgsrc/mk: subst.mk
        pkgsrc/regress/infra-unittests: subst.sh

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 pkgsrc/mk/subst.mk
cvs rdiff -u -r1.15 -r1.16 pkgsrc/regress/infra-unittests/subst.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/mk/subst.mk
diff -u pkgsrc/mk/subst.mk:1.76 pkgsrc/mk/subst.mk:1.77
--- pkgsrc/mk/subst.mk:1.76     Sat Apr 18 11:42:34 2020
+++ pkgsrc/mk/subst.mk  Sat Apr 18 12:21:10 2020
@@ -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 ${S
 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

Index: pkgsrc/regress/infra-unittests/subst.sh
diff -u pkgsrc/regress/infra-unittests/subst.sh:1.15 pkgsrc/regress/infra-unittests/subst.sh:1.16
--- pkgsrc/regress/infra-unittests/subst.sh:1.15        Sat Mar 28 12:08:28 2020
+++ pkgsrc/regress/infra-unittests/subst.sh     Sat Apr 18 12:21:10 2020
@@ -801,7 +801,7 @@ if test_case_begin "SUBST_VARS for varia
                'SUBST_CLASSES+=        vars' \
                'SUBST_STAGE.vars=      pre-configure' \
                'SUBST_FILES.vars=      vars.txt' \
-               'SUBST_VARS.vars=       VAR...... VAR.abcde VAR.() VAR.<>' \
+               'SUBST_VARS.vars=       VAR...... VAR.abcde VAR.() VAR.<> VAR.[]' \
                '' \
                'VAR......=     dots' \
                'VAR.abcde=     letters' \
@@ -817,20 +817,19 @@ if test_case_begin "SUBST_VARS for varia
                "@VAR.()@" \
                "@VAR.<>@" \
                "@VAR.[]@"
+cp "$tmpdir/testcase.mk" /tmp
 
        run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
 
-       # TODO: Why are the angle brackets replaced, but not the parentheses
-       # and square brackets?
        assert_that "vars.txt" --file-is-lines \
                "dots" \
                "letters" \
-               "@VAR.()@" \
+               "parentheses" \
                "angle brackets" \
-               "@VAR.[]@"
+               "square brackets"
        assert_that "stdout" --file-is-lines \
                "=> Substituting \"vars\" in vars.txt"
        assert_that "stderr" --file-is-empty



Home | Main Index | Thread Index | Old Index