diff options
author | Ulrich Drepper <drepper@redhat.com> | 1998-10-12 14:48:58 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1998-10-12 14:48:58 +0000 |
commit | 237abf55939e794c59c4e13a4d7a4c9da65e8956 (patch) | |
tree | d6d5159d87bb053c5642286d95246f9e81e4bd3a | |
parent | 4e10809888937ada32f018e3bac579e55489969c (diff) | |
download | glibc-237abf55939e794c59c4e13a4d7a4c9da65e8956.tar.gz glibc-237abf55939e794c59c4e13a4d7a4c9da65e8956.tar.xz glibc-237abf55939e794c59c4e13a4d7a4c9da65e8956.zip |
(__opendir): Test whether NAME is directory before opening it.
-rw-r--r-- | sysdeps/unix/opendir.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c index 94e8205f25..323b228430 100644 --- a/sysdeps/unix/opendir.c +++ b/sysdeps/unix/opendir.c @@ -45,6 +45,17 @@ __opendir (const char *name) return NULL; } + /* We first have to check whether the name is for a directory. We + cannot do this after the open() call since the open/close operation + performed on, say, a tape device might have undesirable effects. */ + if (stat (name, &statbuf) < 0) + return NULL; + if (! S_ISDIR (statbuf.st_mode)) + { + __set_errno (ENOTDIR); + return NULL; + } + fd = __open (name, O_RDONLY|O_NDELAY); if (fd < 0) return NULL; @@ -52,14 +63,6 @@ __opendir (const char *name) if (__fcntl (fd, F_SETFD, FD_CLOEXEC) < 0) goto lose; - if (fstat (fd, &statbuf) < 0) - goto lose; - if (! S_ISDIR (statbuf.st_mode)) - { - __set_errno (ENOTDIR); - goto lose; - } - dirp = (DIR *) calloc (1, sizeof (DIR)); /* Zero-fill. */ if (dirp == NULL) lose: |