2642b8
diff -up ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c.cdfix2 ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c
2642b8
--- ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c.cdfix2	2013-02-01 16:46:50.441771371 +0100
2642b8
+++ ksh-20120801/src/cmd/ksh93/bltins/cd_pwd.c	2013-02-01 16:57:43.241784024 +0100
2642b8
@@ -61,6 +61,7 @@ int sh_diropenat(Shell_t *shp, int dir,
2642b8
 {
2642b8
 	int fd,shfd;
2642b8
 	int savederrno=errno;
2642b8
+	struct stat fs;
2642b8
 #ifndef AT_FDCWD
2642b8
 	NOT_USED(dir);
2642b8
 #endif
2642b8
@@ -133,6 +134,13 @@ int sh_diropenat(Shell_t *shp, int dir,
2642b8
 
2642b8
 	if(fd < 0)
2642b8
 		return fd;
2642b8
+	
2642b8
+	if (!fstat(fd, &fs) && !S_ISDIR(fs.st_mode))
2642b8
+	{
2642b8
+	  close(fd);
2642b8
+	  errno = ENOTDIR;
2642b8
+	  return -1;
2642b8
+	}
2642b8
 
2642b8
 	/* Move fd to a number > 10 and *register* the fd number with the shell */
2642b8
 	shfd = sh_fcntl(fd, F_dupfd_cloexec, 10);