Hi,

we found a bug in ksh that it does not print any error when 'cd' to directory without execute bit. It does not print any error, it looks like it succeeded despite it did not.

reproducer:
$ mkdir -p a/b/c
$ chmod -x a/b
$ cd a
$ cd b
$ echo $?
0 # should be nonzero
$ pwd
/tmp/a/b
$ ls
b # which means ls was executed from /tmp/a not /tmp/a/b

oneliner version:

ksh -c 'T=$(mktemp -d); chmod -x $T; cd $T; r=$?; cd; rm -rf $T; [ "$r" != 0 ] || { echo FAIL; exit $r; }; echo pass;'

This was caused by changes around 2012-10-10

Fix is attached

Michal

diff -up ksh-20140606/src/cmd/ksh93/bltins/cd_pwd.c.cdfix3 ksh-20140606/src/cmd/ksh93/bltins/cd_pwd.c
--- ksh-20140606/src/cmd/ksh93/bltins/cd_pwd.c.cdfix3	2014-04-30 17:52:37.000000000 +0200
+++ ksh-20140606/src/cmd/ksh93/bltins/cd_pwd.c	2014-06-26 11:57:22.641178856 +0200
@@ -214,7 +214,7 @@ int	b_cd(int argc, char *argv[],Shbltin_
 		if(newdirfd >=0)
 		{
 			/* chdir for directories on HSM/tapeworms may take minutes */
-			if(fchdir(newdirfd) >= 0)
+			if((rval=fchdir(newdirfd)) >= 0)
 			{
 				if(shp->pwdfd >= 0)
 					sh_close(shp->pwdfd);
@@ -240,7 +240,7 @@ int	b_cd(int argc, char *argv[],Shbltin_
 		if(newdirfd >=0)
 		{
 			/* chdir for directories on HSM/tapeworms may take minutes */
-			if(fchdir(newdirfd) >= 0)
+			if((rval=fchdir(newdirfd)) >= 0)
 			{
 				if(shp->pwdfd >= 0)
 					sh_close(shp->pwdfd);
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to