1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-01 10:06:57 +03:00

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.
This commit is contained in:
Adhemerval Zanella
2021-03-11 08:21:06 -03:00
parent e91f44089c
commit 94caafa040
7 changed files with 135 additions and 1 deletions

View File

@ -22,10 +22,16 @@
#include <fcntl.h>
#include <kernel_stat.h>
#include <stat_t64_cp.h>
#include <errno.h>
int
__fstat64_time64 (int fd, struct __stat64_t64 *buf)
{
if (fd < 0)
{
__set_errno (EBADF);
return -1;
}
return __fstatat64_time64 (fd, "", buf, AT_EMPTY_PATH);
}
#if __TIMESIZE != 64
@ -34,6 +40,12 @@ hidden_def (__fstat64_time64)
int
__fstat64 (int fd, struct stat64 *buf)
{
if (fd < 0)
{
__set_errno (EBADF);
return -1;
}
struct __stat64_t64 st_t64;
return __fstat64_time64 (fd, &st_t64)
?: __cp_stat64_t64_stat64 (&st_t64, buf);