diff options
author | bde <bde@FreeBSD.org> | 1996-03-29 12:55:54 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1996-03-29 12:55:54 +0000 |
commit | 21c110b53ce50b60887b305b9bfdd7c611a8d63b (patch) | |
tree | 386b65796ff5b2e8bbf2234765e96dad72d9718f /lib | |
parent | a0131ad117d3896d0855eff1a2bca37c799d82c5 (diff) | |
download | FreeBSD-src-21c110b53ce50b60887b305b9bfdd7c611a8d63b.zip FreeBSD-src-21c110b53ce50b60887b305b9bfdd7c611a8d63b.tar.gz |
stat() before open() because opening of special files may be harmful.
Diffstat (limited to 'lib')
-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 b3c0e09..8cba9cf 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; |