1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

linux: Use INTERNAL_SYSCALL on fstatat{64}

Although not required by the standards, some code expects that a
successful stat call should not set errno.  However since aa03f722f3
'linux: Add {f}stat{at} y2038 support', on 32-bit systems with 32-bit
time_t supporrt, stat implementation will first issues __NR_statx and
if it fails with ENOSYS issue the system stat syscall.

On architecture running on kernel without __NR_statx support the
first call will set the errno to ENOSYS, even when the following stat
syscall might not fail.

This patch fixes by using INTERNAL_SYSCALL and only setting the errno
value when function returns.

Checked on i686-linux-gnu, x86_64-linux-gnu, sparc64-linux-gnu,
sparcv9-linux-gnu, powerpc64-linux-gnu, powerpc64le-linux-gnu,
arm-linux-gnueabihf, and aarch64-linux-gnu.
This commit is contained in:
Adhemerval Zanella
2020-10-14 14:31:38 -03:00
parent 9030377480
commit cb49c65bb5
4 changed files with 34 additions and 28 deletions

View File

@ -26,21 +26,22 @@
int
__fstatat (int fd, const char *file, struct stat *buf, int flag)
{
int r;
# if STAT_IS_KERNEL_STAT
/* New kABIs which uses generic pre 64-bit time Linux ABI, e.g.
csky, nios2 */
int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, buf, flag);
r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, buf, flag);
if (r == 0 && (buf->__st_ino_pad != 0
|| buf->__st_size_pad != 0
|| buf->__st_blocks_pad != 0))
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
return r;
# else
# ifdef __NR_fstatat64
/* Old KABIs with old non-LFS support, e.g. arm, i386, hppa, m68k, mips32,
microblaze, s390, sh, powerpc, and sparc. */
struct stat64 st64;
int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, &st64, flag);
r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, &st64, flag);
if (r == 0)
{
if (! in_ino_t_range (st64.st_ino)
@ -67,15 +68,21 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag)
buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec;
buf->st_ctim.tv_sec = st64.st_ctim.tv_sec;
buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec;
return 0;
}
return r;
# else
/* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */
struct kernel_stat kst;
int r = INLINE_SYSCALL_CALL (newfstatat, fd, file, &kst, flag);
return r ?: __cp_kstat_stat (&kst, buf);
r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, &kst, flag);
if (r == 0)
r = __cp_kstat_stat (&kst, buf);
# endif /* __nr_fstatat64 */
# endif /* STAT_IS_KERNEL_STAT */
return INTERNAL_SYSCALL_ERROR_P (r)
? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
: 0;
}
weak_alias (__fstatat, fstatat)