[PATCH] linux: Use stat_overflow to check overflow in fstatat

Stafford Horne shorne@gmail.com
Thu Jan 14 08:13:49 GMT 2021


After a recent rebase of the OpenRISC port I am working on the build
started to fail with:

    ../sysdeps/unix/sysv/linux/fstatat.c: In function '__fstatat':
    ../sysdeps/unix/sysv/linux/fstatat.c:35:21: error: 'struct stat' has no member named '__st_ino_pad'
       35 |   if (r == 0 && (buf->__st_ino_pad != 0
	  |                     ^~
    ../sysdeps/unix/sysv/linux/fstatat.c:36:24: error: 'struct stat' has no member named '__st_size_pad'
       36 |                  || buf->__st_size_pad != 0
	  |                        ^~
    ../sysdeps/unix/sysv/linux/fstatat.c:37:24: error: 'struct stat' has no member named '__st_blocks_pad'
       37 |                  || buf->__st_blocks_pad != 0))
	  |                        ^~

This seems to be caused by 6073bae64c ("linux: Disentangle fstatat from
fxstatat").  Which introduced the checks for overflow using the
stat->__st_*_pad fields.  These do not exist on all architectures, I
cannot even find any that do exist by grepping code.

The fix is to use the stat_overflow function which only runs the
overflow checks if the pad fields are available.

Note, This is not xstat but I use the xstatover.h header.  I hope that
is not an issue.

Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
 sysdeps/unix/sysv/linux/fstatat.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c
index 59efff615f..5bff931183 100644
--- a/sysdeps/unix/sysv/linux/fstatat.c
+++ b/sysdeps/unix/sysv/linux/fstatat.c
@@ -22,6 +22,7 @@
 
 #if !XSTAT_IS_XSTAT64
 # include <kstat_cp.h>
+# include <xstatover.h>
 
 int
 __fstatat (int fd, const char *file, struct stat *buf, int flag)
@@ -32,10 +33,7 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag)
   /* New kABIs which uses generic pre 64-bit time Linux ABI, e.g.
      csky, nios2  */
   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 ?: stat_overflow (buf);
 # else
 #  ifdef __NR_fstatat64
   /* Old KABIs with old non-LFS support, e.g. arm, i386, hppa, m68k, mips32,
-- 
2.26.2



More information about the Libc-alpha mailing list