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