aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-26 19:56:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-26 19:56:05 +0200
commit0e081d01a8ae37df11af612eb65d858c1c0f28be (patch)
tree7951b68b37925ca81c6fc17b78387c883feab868 /shell
parenta318bba199a08d65c6fb804e26d0993068a4ba16 (diff)
downloadbusybox-w32-0e081d01a8ae37df11af612eb65d858c1c0f28be.tar.gz
busybox-w32-0e081d01a8ae37df11af612eb65d858c1c0f28be.tar.bz2
busybox-w32-0e081d01a8ae37df11af612eb65d858c1c0f28be.zip
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>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/shell/ash.c b/shell/ash.c
index e47c47850..8bf02e6a7 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2638,7 +2638,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
2638 if (!dest) 2638 if (!dest)
2639 dest = nullstr; 2639 dest = nullstr;
2640 if (*dest == '/') 2640 if (*dest == '/')
2641 goto step7; 2641 goto step6;
2642 if (*dest == '.') { 2642 if (*dest == '.') {
2643 c = dest[1]; 2643 c = dest[1];
2644 dotdot: 2644 dotdot:
@@ -2655,13 +2655,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
2655 if (!*dest) 2655 if (!*dest)
2656 dest = "."; 2656 dest = ".";
2657 path = bltinlookup("CDPATH"); 2657 path = bltinlookup("CDPATH");
2658 if (!path) { 2658 while (path) {
2659 step6:
2660 step7:
2661 p = dest;
2662 goto docd;
2663 }
2664 do {
2665 c = *path; 2659 c = *path;
2666 p = path_advance(&path, dest); 2660 p = path_advance(&path, dest);
2667 if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) { 2661 if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
@@ -2670,9 +2664,15 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
2670 docd: 2664 docd:
2671 if (!docd(p, flags)) 2665 if (!docd(p, flags))
2672 goto out; 2666 goto out;
2673 break; 2667 goto err;
2674 } 2668 }
2675 } while (path); 2669 }
2670
2671 step6:
2672 p = dest;
2673 goto docd;
2674
2675 err:
2676 ash_msg_and_raise_error("can't cd to %s", dest); 2676 ash_msg_and_raise_error("can't cd to %s", dest);
2677 /* NOTREACHED */ 2677 /* NOTREACHED */
2678 out: 2678 out: