Hi,
it's probably fixed already, but latest alpha 2012-11-21 allows cd to file:
$ ls -l fedora-server-ca.cert
-rw-rw-r--. 1 mhlavink mhlavink 3845 Feb 7 2011 fedora-server-ca.cert
$ cd fedora-server-ca.cert
$ echo $?
0
$ cd fedora-server-ca.cert
$ pwd
/home/mhlavink/fedora-server-ca.cert/fedora-server-ca.cert
In cd_pwd.c: b_cd(...)
it get file descriptor rval = ... = sh_diropenat (...)
and later it tries to fchdir(...) to this, it fails with ENOTDIR,
but it just means it does not goto success. It continues with extra
code, and gets to the last rval<0 check. But because file exists, file
descriptor is valid and it does not print any error.
I changed sh_diropenat(...) to fstat file desriptor whether it is a
directory or not and return error when it isn't.
Attached patch works for me.
Michal
diff -up ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c.cdfix2 ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c
--- ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c.cdfix2 2013-02-01 16:46:50.441771371 +0100
+++ ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c 2013-02-01 16:57:43.241784024 +0100
@@ -61,6 +61,7 @@ int sh_diropenat(Shell_t *shp, int dir,
{
int fd,shfd;
int savederrno=errno;
+ struct stat fs;
#ifndef AT_FDCWD
NOT_USED(dir);
#endif
@@ -133,6 +134,13 @@ int sh_diropenat(Shell_t *shp, int dir,
if(fd < 0)
return fd;
+
+ if (!fstat(fd, &fs) && !S_ISDIR(fs.st_mode))
+ {
+ close(fd);
+ errno = ENOTDIR;
+ return -1;
+ }
/* Move fd to a number > 10 and *register* the fd number with the shell */
shfd = sh_fcntl(fd, F_dupfd_cloexec, 10);
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers