Blame SOURCES/ksh-20120801-cdfix2.patch

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