summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-08-22 21:18:21 +0000
committerjilles <jilles@FreeBSD.org>2010-08-22 21:18:21 +0000
commit44306000bd39088d3ea3cb9ea48d5e8e2a2db956 (patch)
treefe838f436df897b73945aca0f1988908713acfe4
parent46ef2238957d432f05edefd9ba4e01694a007942 (diff)
downloadFreeBSD-src-44306000bd39088d3ea3cb9ea48d5e8e2a2db956.zip
FreeBSD-src-44306000bd39088d3ea3cb9ea48d5e8e2a2db956.tar.gz
sh: Remove remnants of '!!' to negate pattern.
This Almquist extension was disabled long ago. In pathname generation, components starting with '!!' were treated as containing wildcards, causing unnecessary readdir (which could fail, causing pathname generation to fail while it should not).
-rw-r--r--bin/sh/expand.c19
-rw-r--r--tools/regression/bin/sh/expansion/pathname4.028
2 files changed, 30 insertions, 17 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index fded6da..7354010 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -109,7 +109,6 @@ STATIC void expmeta(char *, char *);
STATIC void addfname(char *);
STATIC struct strlist *expsort(struct strlist *);
STATIC struct strlist *msort(struct strlist *, int);
-STATIC int pmatch(const char *, const char *, int);
STATIC char *cvtnum(int, char *);
STATIC int collate_range_cmp(int, int);
@@ -1101,7 +1100,7 @@ expandmeta(struct strlist *str, int flag __unused)
for (;;) { /* fast check for meta chars */
if ((c = *p++) == '\0')
goto nometa;
- if (c == '*' || c == '?' || c == '[' || c == '!')
+ if (c == '*' || c == '?' || c == '[')
break;
}
savelastp = exparg.lastp;
@@ -1168,8 +1167,6 @@ expmeta(char *enddir, char *name)
break;
}
}
- } else if (*p == '!' && p[1] == '!' && (p == name || p[-1] == '/')) {
- metaflag = 1;
} else if (*p == '\0')
break;
else if (*p == CTLQUOTEMARK)
@@ -1353,18 +1350,6 @@ msort(struct strlist *list, int len)
int
patmatch(const char *pattern, const char *string, int squoted)
{
-#ifdef notdef
- if (pattern[0] == '!' && pattern[1] == '!')
- return 1 - pmatch(pattern + 2, string);
- else
-#endif
- return pmatch(pattern, string, squoted);
-}
-
-
-STATIC int
-pmatch(const char *pattern, const char *string, int squoted)
-{
const char *p, *q;
char c;
@@ -1406,7 +1391,7 @@ pmatch(const char *pattern, const char *string, int squoted)
}
}
do {
- if (pmatch(p, q, squoted))
+ if (patmatch(p, q, squoted))
return 1;
if (squoted && *q == CTLESC)
q++;
diff --git a/tools/regression/bin/sh/expansion/pathname4.0 b/tools/regression/bin/sh/expansion/pathname4.0
new file mode 100644
index 0000000..18269c4
--- /dev/null
+++ b/tools/regression/bin/sh/expansion/pathname4.0
@@ -0,0 +1,28 @@
+# $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 !!a
+touch !!a/fff
+
+chmod u-r .
+check '!!a/ff*' '!!a/fff'
+chmod u+r .
+
+exit $((failures != 0))
OpenPOWER on IntegriCloud