Without this fix, compilers can generate incorrect machine code
for functions that call to fstatat-like functions, as the
compilers incorrectly assume that the calls’ arguments cannot be
null pointers.  This assumption became false with the release of
Linux kernel 6.11 (2024).
* lib/sys_stat.in.h (fchmodat, fstatat, utimensat):
* lib/unistd.in.h (faccessat, fchownat): Do not mark file args
with _GL_ARG_NONNULL, as the args are allowed to be null pointers
in Linux kernel 6.11+, possibly with glibc 2.41+ involved.
---
 ChangeLog         | 11 +++++++++++
 lib/sys_stat.in.h | 28 ++++++++++++++--------------
 lib/unistd.in.h   | 32 ++++++++++++++++----------------
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4882598f43..20459c0447 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2026-06-16  Paul Eggert  <[email protected]>
 
+       fstatat etc.: fix wrong machine code for calls
+       Without this fix, compilers can generate incorrect machine code
+       for functions that call to fstatat-like functions, as the
+       compilers incorrectly assume that the calls’ arguments cannot be
+       null pointers.  This assumption became false with the release of
+       Linux kernel 6.11 (2024).
+       * lib/sys_stat.in.h (fchmodat, fstatat, utimensat):
+       * lib/unistd.in.h (faccessat, fchownat): Do not mark file args
+       with _GL_ARG_NONNULL, as the args are allowed to be null pointers
+       in Linux kernel 6.11+, possibly with glibc 2.41+ involved.
+
        euidaccess-tests: link with test_euidaccess_LDADD
        * modules/euidaccess-tests (test_euidaccess_LDADD):
        New macro.  Needed for Solaris 10.
diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h
index deed21cdf3..567dffa620 100644
--- a/lib/sys_stat.in.h
+++ b/lib/sys_stat.in.h
@@ -480,18 +480,18 @@ _GL_CXXALIASWARN (chmod);
 #   define fchmodat rpl_fchmodat
 #  endif
 _GL_FUNCDECL_RPL (fchmodat, int,
-                  (int fd, char const *file, mode_t mode, int flag),
-                  _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_NODISCARD);
+                  (int fd, char const *file, mode_t mode, int flags),
+                  _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (fchmodat, int,
-                  (int fd, char const *file, mode_t mode, int flag));
+                  (int fd, char const *file, mode_t mode, int flags));
 # else
 #  if !@HAVE_FCHMODAT@
 _GL_FUNCDECL_SYS (fchmodat, int,
-                  (int fd, char const *file, mode_t mode, int flag),
-                  _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_NODISCARD);
+                  (int fd, char const *file, mode_t mode, int flags),
+                  _GL_ATTRIBUTE_NODISCARD);
 #  endif
 _GL_CXXALIAS_SYS (fchmodat, int,
-                  (int fd, char const *file, mode_t mode, int flag));
+                  (int fd, char const *file, mode_t mode, int flags));
 # endif
 _GL_CXXALIASWARN (fchmodat);
 #elif defined GNULIB_POSIXCHECK
@@ -542,7 +542,7 @@ _GL_WARN_ON_USE (fstat, "fstat has portability problems - "
 _GL_FUNCDECL_RPL (fstatat, int,
                   (int fd, char const *restrict name, struct stat *restrict st,
                    int flags),
-                  _GL_ARG_NONNULL ((2, 3)));
+                  _GL_ARG_NONNULL ((3)));
 _GL_CXXALIAS_RPL (fstatat, int,
                   (int fd, char const *restrict name, struct stat *restrict st,
                    int flags));
@@ -551,7 +551,7 @@ _GL_CXXALIAS_RPL (fstatat, int,
 _GL_FUNCDECL_SYS (fstatat, int,
                   (int fd, char const *restrict name, struct stat *restrict st,
                    int flags),
-                  _GL_ARG_NONNULL ((2, 3)));
+                  _GL_ARG_NONNULL ((3)));
 #  endif
 _GL_CXXALIAS_SYS (fstatat, int,
                   (int fd, char const *restrict name, struct stat *restrict st,
@@ -966,18 +966,18 @@ _GL_CXXALIASWARN (umask);
 #   define utimensat rpl_utimensat
 #  endif
 _GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
-                                   struct timespec const times[2], int flag),
-                                  _GL_ARG_NONNULL ((2)));
+                                   struct timespec const times[2], int flags),
+                  );
 _GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
-                                   struct timespec const times[2], int flag));
+                                   struct timespec const times[2], int flags));
 # else
 #  if !@HAVE_UTIMENSAT@
 _GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
-                                   struct timespec const times[2], int flag),
-                                  _GL_ARG_NONNULL ((2)));
+                                   struct timespec const times[2], int flags),
+                  );
 #  endif
 _GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
-                                   struct timespec const times[2], int flag));
+                                   struct timespec const times[2], int flags));
 # endif
 # if __GLIBC__ >= 2 && @HAVE_UTIMENSAT@
 _GL_CXXALIASWARN (utimensat);
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index f7e4450ced..8f40c19e2a 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -930,18 +930,18 @@ _GL_CXXALIASWARN (execvpe);
 #   define faccessat rpl_faccessat
 #  endif
 _GL_FUNCDECL_RPL (faccessat, int,
-                  (int fd, char const *name, int mode, int flag),
-                  _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_NODISCARD);
+                  (int fd, char const *name, int mode, int flags),
+                  _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (faccessat, int,
-                  (int fd, char const *name, int mode, int flag));
+                  (int fd, char const *name, int mode, int flags));
 # else
 #  if !@HAVE_FACCESSAT@
 _GL_FUNCDECL_SYS (faccessat, int,
-                  (int fd, char const *file, int mode, int flag),
-                  _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_NODISCARD);
+                  (int fd, char const *file, int mode, int flags),
+                  _GL_ATTRIBUTE_NODISCARD);
 #  endif
 _GL_CXXALIAS_SYS (faccessat, int,
-                  (int fd, char const *file, int mode, int flag));
+                  (int fd, char const *file, int mode, int flags));
 # endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (faccessat);
@@ -997,18 +997,18 @@ _GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
 #   define fchownat rpl_fchownat
 #  endif
 _GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
-                                  uid_t owner, gid_t group, int flag),
-                                 _GL_ARG_NONNULL ((2)) 
_GL_ATTRIBUTE_NODISCARD);
+                                  uid_t owner, gid_t group, int flags),
+                  _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
-                                  uid_t owner, gid_t group, int flag));
+                                  uid_t owner, gid_t group, int flags));
 # else
 #  if !@HAVE_FCHOWNAT@
 _GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
-                                  uid_t owner, gid_t group, int flag),
-                                 _GL_ARG_NONNULL ((2)) 
_GL_ATTRIBUTE_NODISCARD);
+                                  uid_t owner, gid_t group, int flags),
+                  _GL_ATTRIBUTE_NODISCARD);
 #  endif
 _GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
-                                  uid_t owner, gid_t group, int flag));
+                                  uid_t owner, gid_t group, int flags));
 # endif
 _GL_CXXALIASWARN (fchownat);
 #elif defined GNULIB_POSIXCHECK
@@ -1728,21 +1728,21 @@ _GL_WARN_ON_USE (link, "link is unportable - "
 #  endif
 _GL_FUNCDECL_RPL (linkat, int,
                   (int fd1, const char *path1, int fd2, const char *path2,
-                   int flag),
+                   int flags),
                   _GL_ARG_NONNULL ((2, 4)) _GL_ATTRIBUTE_NODISCARD);
 _GL_CXXALIAS_RPL (linkat, int,
                   (int fd1, const char *path1, int fd2, const char *path2,
-                   int flag));
+                   int flags));
 # else
 #  if !@HAVE_LINKAT@
 _GL_FUNCDECL_SYS (linkat, int,
                   (int fd1, const char *path1, int fd2, const char *path2,
-                   int flag),
+                   int flags),
                   _GL_ARG_NONNULL ((2, 4)) _GL_ATTRIBUTE_NODISCARD);
 #  endif
 _GL_CXXALIAS_SYS (linkat, int,
                   (int fd1, const char *path1, int fd2, const char *path2,
-                   int flag));
+                   int flags));
 # endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (linkat);
-- 
2.54.0


Reply via email to