From db98aac00aa4b78e8811da43a1a6366f4feff158 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 21 Aug 2011 12:46:44 -0700 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 '..'. Obtained-from: FreeBSD 222381 --- bin/sh/cd.c | 7 +++++-- tools/regression/bin/sh/builtins/cd6.0 | 10 ++++++++++ tools/regression/bin/sh/builtins/cd7.0 | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) 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 fdbeff1dc0..8396df67f4 100644 --- a/bin/sh/cd.c +++ b/bin/sh/cd.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)cd.c 8.2 (Berkeley) 5/4/95 - * $FreeBSD: src/bin/sh/cd.c,v 1.47 2011/05/25 21:38:16 jilles Exp $ + * $FreeBSD: src/bin/sh/cd.c,v 1.48 2011/05/27 20:01:46 jilles Exp $ */ #include @@ -122,7 +122,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 0000000000..664f11de87 --- /dev/null +++ b/tools/regression/bin/sh/builtins/cd6.0 @@ -0,0 +1,10 @@ +# $FreeBSD: src/tools/regression/bin/sh/builtins/cd6.0,v 1.1 2011/05/27 20:01:46 jilles Exp $ + +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 0000000000..0a9c9d813a --- /dev/null +++ b/tools/regression/bin/sh/builtins/cd7.0 @@ -0,0 +1,15 @@ +# $FreeBSD: src/tools/regression/bin/sh/builtins/cd7.0,v 1.1 2011/05/27 20:01:46 jilles Exp $ + +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 ] -- 2.41.0