diff options
| author | Bruce Evans <bde@FreeBSD.org> | 1996-03-29 12:55:54 +0000 |
|---|---|---|
| committer | Bruce Evans <bde@FreeBSD.org> | 1996-03-29 12:55:54 +0000 |
| commit | 0b50c8d6537516aaf03902e262949f8a3fc62500 (patch) | |
| tree | 386b65796ff5b2e8bbf2234765e96dad72d9718f /lib/libc | |
| parent | a1fbfdff1425b1a3739d34ac197690f9afde4e86 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/gen/opendir.c | 10 |
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; |
