summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-05-11 23:19:28 +0000
committerjilles <jilles@FreeBSD.org>2010-05-11 23:19:28 +0000
commitc49fe4933f95753b15b11b89f9d209f08c64153f (patch)
tree930ef61883d224d336b660f9537781e1ffb4419e /tools
parentc1a464818797468501a519a2fd01737052ade6dd (diff)
downloadFreeBSD-src-c49fe4933f95753b15b11b89f9d209f08c64153f.zip
FreeBSD-src-c49fe4933f95753b15b11b89f9d209f08c64153f.tar.gz
sh: Fix pathname expansion with quoted slashes like *\/.
These are git commits 36f0fa8fcbc8c7b2b194addd29100fb40e73e4e9 and d6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4 in dash. Because this is the first code I'm importing from dash to expand.c, add the Herbert Xu copyright notice which is in dash's expand.c. When pathname expanding *\/, the CTLESC representing the quoted state was erroneously taken as part of the * pathname component. This CTLESC was then seen by the pattern matching code as escaping the '\0' terminating the string. The code is slightly different because dash converts the CTLESC characters to backslashes and removes all the other CTL* characters to allow substituting glob(3). The effect of the bug was also slightly different from dash (where nothing matched at all). Because a CTLESC can escape a '\0' in some way, whether files were included despite the bug depended on memory that should not be read. In particular, on many machines /*\/ expanded to a strict subset of what /*/ expanded to. Example: echo /*"/null" This should print /dev/null, not /*/null. PR: bin/146378 Obtained from: dash
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/bin/sh/expansion/pathname2.031
1 files changed, 31 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/expansion/pathname2.0 b/tools/regression/bin/sh/expansion/pathname2.0
new file mode 100644
index 0000000..8a884ff
--- /dev/null
+++ b/tools/regression/bin/sh/expansion/pathname2.0
@@ -0,0 +1,31 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+ testcase=$1
+ expect=$2
+ eval "set -- $testcase"
+ actual="$*"
+ if [ "$actual" != "$expect" ]; then
+ failures=$((failures+1))
+ printf '%s\n' "For $testcase, expected $expect actual $actual"
+ fi
+}
+
+set -e
+T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX)
+trap 'rm -rf $T' 0
+cd -P $T
+
+mkdir testdir testdir2 'testdir/*' 'testdir/?' testdir/a testdir/b testdir2/b
+mkdir testdir2/.c
+touch testf 'testdir/*/1' 'testdir/?/1' testdir/a/1 testdir/b/1 testdir2/b/.a
+
+check '*\/' 'testdir/ testdir2/'
+check '"testdir/"*"/1"' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1'
+check '"testdir/"*"/"*' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1'
+check '"testdir/"*\/*' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1'
+check '"testdir"*"/"*"/"*' 'testdir/*/1 testdir/?/1 testdir/a/1 testdir/b/1'
+
+exit $((failures != 0))
OpenPOWER on IntegriCloud