ash: [CD] Lookup PWD after going through CDPATH
Upstream commit: Date: Mon, 31 Aug 2009 22:06:41 +1000 [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> function old new delta cdcmd 667 680 +13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
a318bba199
commit
0e081d01a8
20
shell/ash.c
20
shell/ash.c
@ -2638,7 +2638,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
if (!dest)
|
||||
dest = nullstr;
|
||||
if (*dest == '/')
|
||||
goto step7;
|
||||
goto step6;
|
||||
if (*dest == '.') {
|
||||
c = dest[1];
|
||||
dotdot:
|
||||
@ -2655,13 +2655,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
if (!*dest)
|
||||
dest = ".";
|
||||
path = bltinlookup("CDPATH");
|
||||
if (!path) {
|
||||
step6:
|
||||
step7:
|
||||
p = dest;
|
||||
goto docd;
|
||||
}
|
||||
do {
|
||||
while (path) {
|
||||
c = *path;
|
||||
p = path_advance(&path, dest);
|
||||
if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
|
||||
@ -2670,9 +2664,15 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
docd:
|
||||
if (!docd(p, flags))
|
||||
goto out;
|
||||
break;
|
||||
goto err;
|
||||
}
|
||||
} while (path);
|
||||
}
|
||||
|
||||
step6:
|
||||
p = dest;
|
||||
goto docd;
|
||||
|
||||
err:
|
||||
ash_msg_and_raise_error("can't cd to %s", dest);
|
||||
/* NOTREACHED */
|
||||
out:
|
||||
|
Loading…
Reference in New Issue
Block a user