From 64fa41f3e1e9db4799e35b80c888de34e459bb11 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Fri, 27 May 2011 20:01:46 +0000 Subject: [PATCH] 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. --- bin/sh/cd.c | 5 ++++- tools/regression/bin/sh/builtins/cd6.0 | 10 ++++++++++ tools/regression/bin/sh/builtins/cd7.0 | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tools/regression/bin/sh/builtins/cd6.0 create mode 100644 tools/regression/bin/sh/builtins/cd7.0 diff --git a/bin/sh/cd.c b/bin/sh/cd.c index 2cd9dafa5d57..b1b0fc015e9e 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 000000000000..083a06190e64 --- /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 000000000000..9adda86c1aed --- /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 ]