]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
The futimesat syscall wrapper doesn't handle AT_FDCWD
authorMartin Cermak <mcermak@redhat.com>
Tue, 5 Aug 2025 14:54:54 +0000 (16:54 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 6 Aug 2025 17:13:19 +0000 (19:13 +0200)
Update futimesat syscall wrapper so that it doesn't consider the
special value AT_FDCWD (-100) an invalid file descriptor.

https://bugs.kde.org/show_bug.cgi?id=507868

NEWS
coregrind/m_syswrap/syswrap-linux.c

diff --git a/NEWS b/NEWS
index 6b21446ec718f5c9e6039a976697e33fbf8ccccc..a38078277112058bff3253bdefb10932551533f4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 506967  Implement and override mallinfo2
 506970  mmap needs an EBADF fd_allowed check
 507173  s390x: Crash when constant folding is disabled
+507868  futimesat doesn't handle AT_FDCWD
 507873  Make fchmodat and fchmodat2 syscall wrappers accept AT_FDCWD
 507897  Allow for patching LTP sources
 
index 96d22e6f4406d2c3245b67b31b5f73b7705c1df4..1033d2409d32c8c59a75f6965db4ed7fc4003f63 100644 (file)
@@ -6213,16 +6213,23 @@ PRE(sys_fchownat)
 PRE(sys_futimesat)
 {
    FUSE_COMPATIBLE_MAY_BLOCK();
-   PRINT("sys_futimesat ( %ld, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",
-         SARG1, ARG2, (HChar*)(Addr)ARG2, ARG3);
+   Int arg_1 = (Int)ARG1;
+   const HChar *path = (const HChar*) ARG2;
+   PRINT("sys_futimesat ( %d, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x )",
+         arg_1, ARG2, path, ARG3);
    PRE_REG_READ3(long, "futimesat",
                  int, dfd, char *, filename, struct timeval *, tvp);
    if (ARG2 != 0)
       PRE_MEM_RASCIIZ( "futimesat(filename)", ARG2 );
    if (ARG3 != 0)
       PRE_MEM_READ( "futimesat(tvp)", ARG3, 2 * sizeof(struct vki_timeval) );
-   if ( !ML_(fd_allowed)(SARG1, "futimesat", tid, False) )
-     SET_STATUS_Failure( VKI_EBADF );
+   if (ML_(safe_to_deref) (path, 1)) {
+      /* If pathname is relative and dirfd is the special value AT_FDCWD, then pathname is interpreted ... */
+      if (path[0] != '/')
+         if ( arg_1 != VKI_AT_FDCWD && !ML_(fd_allowed)(arg_1, "futimesat", tid, False) )
+            SET_STATUS_Failure( VKI_EBADF );
+      /* If pathname is absolute, then dirfd is ignored. */
+   }
 
 }