From 94caafa040e4b4289c968cd70d53041b1463ac4d Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 11 Mar 2021 08:21:06 -0300 Subject: 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. --- io/fstat.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'io/fstat.c') diff --git a/io/fstat.c b/io/fstat.c index dc11736..17f31bf 100644 --- a/io/fstat.c +++ b/io/fstat.c @@ -16,10 +16,16 @@ . */ #include +#include int __fstat (int fd, struct stat *buf) { + if (fd < 0) + { + __set_errno (EBADF); + return -1; + } return __fstatat (fd, "", buf, AT_EMPTY_PATH); } -- cgit v1.1