diff options
author | jilles <jilles@FreeBSD.org> | 2011-05-27 20:01:46 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2011-05-27 20:01:46 +0000 |
commit | 5c7c156d1e87d7f343acc5808137d89bd70c871b (patch) | |
tree | 8a0532484b27c08786f29c30bbb2d974b0366354 | |
parent | 5499b0b9d54eff4cc9b3a16b9a1ed77df9d1f9d9 (diff) | |
download | FreeBSD-src-5c7c156d1e87d7f343acc5808137d89bd70c871b.zip FreeBSD-src-5c7c156d1e87d7f343acc5808137d89bd70c871b.tar.gz |
sh: Correct criterion for using CDPATH in cd.
CDPATH should be ignored not only for pathnames starting with '/' but also
for pathnames whose first component is '.' or '..'.
The man page already describes this behaviour.
-rw-r--r-- | bin/sh/cd.c | 5 | ||||
-rw-r--r-- | tools/regression/bin/sh/builtins/cd6.0 | 10 | ||||
-rw-r--r-- | tools/regression/bin/sh/builtins/cd7.0 | 15 |
3 files changed, 29 insertions, 1 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c index 2cd9daf..b1b0fc0 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -123,7 +123,10 @@ cdcmd(int argc, char **argv) else dest = "."; } - if (*dest == '/' || (path = bltinlookup("CDPATH", 1)) == NULL) + if (dest[0] == '/' || + (dest[0] == '.' && (dest[1] == '/' || dest[1] == '\0')) || + (dest[0] == '.' && dest[1] == '.' && (dest[2] == '/' || dest[2] == '\0')) || + (path = bltinlookup("CDPATH", 1)) == NULL) path = nullstr; while ((p = padvance(&path, dest)) != NULL) { if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) { diff --git a/tools/regression/bin/sh/builtins/cd6.0 b/tools/regression/bin/sh/builtins/cd6.0 new file mode 100644 index 0000000..083a061 --- /dev/null +++ b/tools/regression/bin/sh/builtins/cd6.0 @@ -0,0 +1,10 @@ +# $FreeBSD$ + +set -e +cd -P /bin +d=$PWD +CDPATH=/: +cd -P . +[ "$d" = "$PWD" ] +cd -P ./ +[ "$d" = "$PWD" ] diff --git a/tools/regression/bin/sh/builtins/cd7.0 b/tools/regression/bin/sh/builtins/cd7.0 new file mode 100644 index 0000000..9adda86 --- /dev/null +++ b/tools/regression/bin/sh/builtins/cd7.0 @@ -0,0 +1,15 @@ +# $FreeBSD$ + +set -e +cd /usr/bin +[ "$PWD" = /usr/bin ] +CDPATH=/: +cd . +[ "$PWD" = /usr/bin ] +cd ./ +[ "$PWD" = /usr/bin ] +cd .. +[ "$PWD" = /usr ] +cd /usr/bin +cd ../ +[ "$PWD" = /usr ] |