diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-08-10 08:56:00 -0300 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-11-30 13:37:04 -0300 |
commit | 4e16d89866e660426438238a47c2345bdc47dd97 (patch) | |
tree | a5549e72fcba4d943e8a8dd98835dbb32b444c30 /sysdeps/unix/sysv/linux/fdopendir.c | |
parent | 807849965bbdeaa9b0a8f675d098efc520eeaaa8 (diff) | |
download | glibc-4e16d89866e660426438238a47c2345bdc47dd97.tar glibc-4e16d89866e660426438238a47c2345bdc47dd97.tar.gz glibc-4e16d89866e660426438238a47c2345bdc47dd97.tar.bz2 glibc-4e16d89866e660426438238a47c2345bdc47dd97.zip |
linux: Make fdopendir fail with O_PATH (BZ 30373)
It is not strictly required by the POSIX, since O_PATH is a Linux
extension, but it is QoI to fail early instead of at readdir. Also
the check is free, since fdopendir already checks if the file
descriptor is opened for read.
Checked on x86_64-linux-gnu.
Diffstat (limited to 'sysdeps/unix/sysv/linux/fdopendir.c')
-rw-r--r-- | sysdeps/unix/sysv/linux/fdopendir.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/sysdeps/unix/sysv/linux/fdopendir.c b/sysdeps/unix/sysv/linux/fdopendir.c index 861345396c..707fb5960e 100644 --- a/sysdeps/unix/sysv/linux/fdopendir.c +++ b/sysdeps/unix/sysv/linux/fdopendir.c @@ -37,10 +37,16 @@ __fdopendir (int fd) return NULL; } - /* Make sure the descriptor allows for reading. */ int flags = __fcntl64_nocancel (fd, F_GETFL); if (__glibc_unlikely (flags == -1)) return NULL; + /* Fail early for descriptors opened with O_PATH. */ + if (__glibc_unlikely (flags & O_PATH)) + { + __set_errno (EBADF); + return NULL; + } + /* Make sure the descriptor allows for reading. */ if (__glibc_unlikely ((flags & O_ACCMODE) == O_WRONLY)) { __set_errno (EINVAL); |