aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen/opendir.c
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>1996-03-29 12:55:54 +0000
committerBruce Evans <bde@FreeBSD.org>1996-03-29 12:55:54 +0000
commit0b50c8d6537516aaf03902e262949f8a3fc62500 (patch)
tree386b65796ff5b2e8bbf2234765e96dad72d9718f /lib/libc/gen/opendir.c
parenta1fbfdff1425b1a3739d34ac197690f9afde4e86 (diff)
downloadsrc-0b50c8d6537516aaf03902e262949f8a3fc62500.tar.gz
src-0b50c8d6537516aaf03902e262949f8a3fc62500.zip
stat() before open() because opening of special files may be harmful.
Notes
Notes: svn path=/head/; revision=14910
Diffstat (limited to 'lib/libc/gen/opendir.c')
-rw-r--r--lib/libc/gen/opendir.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index b3c0e096d67e..8cba9cf75390 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -56,6 +56,16 @@ opendir(name)
int saved_errno;
struct stat sb;
+ /*
+ * stat() before open() because opening of special files may be
+ * harmful. fstat() after open because the file may have changed.
+ */
+ if (stat(name, &sb) != 0)
+ return NULL;
+ if (!S_ISDIR(sb.st_mode)) {
+ errno = ENOTDIR;
+ return NULL;
+ }
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
return NULL;
dirp = NULL;