about summary refs log tree commit diff
path: root/io/fstat.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-03-11 08:21:06 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-03-11 10:53:50 -0300
commit32b9280f1d9f78e8fa3874e22f4d9a76460ee02a (patch)
treef06cd301baac6879fe96a71a1abce2f839c5ccf9 /io/fstat.c
parenta151f2e05a64727c552a297d129b8ef242ffb3b6 (diff)
downloadglibc-32b9280f1d9f78e8fa3874e22f4d9a76460ee02a.tar.gz
glibc-32b9280f1d9f78e8fa3874e22f4d9a76460ee02a.tar.xz
glibc-32b9280f1d9f78e8fa3874e22f4d9a76460ee02a.zip
io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
Now that fstat is implemented on top fstatat we need to handle negative
inputs.  The implementation now rejects AT_FDCWD, which would otherwise
be accepted by the kernel.

Checked on x86_64-linux-gnu and on i686-linux-gnu.

(cherry picked from commit 94caafa040e4b4289c968cd70d53041b1463ac4d)
Diffstat (limited to 'io/fstat.c')
-rw-r--r--io/fstat.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/io/fstat.c b/io/fstat.c
index dc117361ff..17f31bf3b3 100644
--- a/io/fstat.c
+++ b/io/fstat.c
@@ -16,10 +16,16 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sys/stat.h>
+#include <errno.h>
 
 int
 __fstat (int fd, struct stat *buf)
 {
+  if (fd < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
   return __fstatat (fd, "", buf, AT_EMPTY_PATH);
 }