aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-08-31 22:06:41 +1000
committermaximilian attems <max@stro.at>2010-03-22 00:29:17 +0100
commit66c4c006f26329f41f0f418672351eb8c3dc2154 (patch)
treee564b12eb3297e6cbee249d8599285b2cdcc3548
parent013f9e80f1f5061a297de1a62f0408c6a78f4400 (diff)
downloadklibc-66c4c006f26329f41f0f418672351eb8c3dc2154.tar.gz
[klibc] [CD] Lookup PWD after going through CDPATH
On Tue, Jul 14, 2009 at 09:39:03PM +0000, Eric Blake wrote: > For the cd command, POSIX 2008 requires that after all pathnames in CDPATH > have been tested and failed in step 5, then step 6 interprets the directory > argument relative to PWD. In other words, this demonstrates a bug: > > $ dash -c 'cd /tmp; mkdir -p foo; CDPATH=oops; cd foo; echo $?; pwd' > cd: 1: can't cd to foo > 2 > /tmp > > while bash gets it correct: > > $ bash -c 'cd /tmp; mkdir -p foo; CDPATH=oops; cd foo; echo $?; pwd' > 0 > /tmp/foo This patch fixes the problem. Reported-by: Eric Blake <ebb9@byu.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/dash/cd.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/usr/dash/cd.c b/usr/dash/cd.c
index fc80035faa155..8a23110e62c81 100644
--- a/usr/dash/cd.c
+++ b/usr/dash/cd.c
@@ -106,7 +106,7 @@ cdcmd(int argc, char **argv)
if (!dest)
dest = nullstr;
if (*dest == '/')
- goto step7;
+ goto step6;
if (*dest == '.') {
c = dest[1];
dotdot:
@@ -122,13 +122,8 @@ dotdot:
}
if (!*dest)
dest = ".";
- if (!(path = bltinlookup("CDPATH"))) {
-step6:
-step7:
- p = dest;
- goto docd;
- }
- do {
+ path = bltinlookup("CDPATH");
+ while (path) {
c = *path;
p = padvance(&path, dest);
if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
@@ -137,9 +132,15 @@ step7:
docd:
if (!docd(p, flags))
goto out;
- break;
+ goto err;
}
- } while (path);
+ }
+
+step6:
+ p = dest;
+ goto docd;
+
+err:
sh_error("can't cd to %s", dest);
/* NOTREACHED */
out: