stat() before open() because opening of special files may be harmful.

This commit is contained in:
bde 1996-03-29 12:55:54 +00:00
parent 3e694fd3e8
commit 19d4cb63d2

View File

@ -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;