]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Don't warn about fcntl F_GETFD with --track-fds
authorMark Wielaard <mark@klomp.org>
Fri, 24 Oct 2025 16:31:31 +0000 (18:31 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 24 Oct 2025 16:34:20 +0000 (18:34 +0200)
fcntl F_GETFD is used to check if a file descriptor is valid, so only
make sure it isn't a valgrind fd, otherwise we might warn, with
--track-fds=bad for any bad fd.

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

NEWS
coregrind/m_syswrap/syswrap-linux.c

diff --git a/NEWS b/NEWS
index ff72ff1587346c1f91d0c607b64e151d65367009..bf7d42ec2ecde3370e44c4a4e569818d6db4ea22 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -208,6 +208,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 509643  Add missing s390x-linux syswraps
 510169  Update the LTP version in valgrind testsuite to 20250930
 510292  Silence false positive failure of LTP munmap01
+510436  Don't warn about fcntl F_GETFD with --track-fds
 510694  Handle qExecAndArgs remote protocol packet
 
 To see details of a given bug, visit
index 341fa96ecd07ae83c45fbdf50ce2a0c34da3ea2e..e8b200385b8f1b64ce948aeb8a6a342cf85f1fcd 100644 (file)
@@ -7447,7 +7447,16 @@ PRE(sys_fcntl)
 #  endif
       *flags |= SfMayBlock;
 
-   if (!ML_(fd_allowed)(ARG1, "fcntl", tid, False)) {
+   /* F_GETFD is used to check if a file descriptor is valid, so only
+      make sure it isn't a valgrind fd, otherwise we might warn, with
+      --track-fds=bad for any bad fd.  */
+   if (ARG2 == VKI_F_GETFD) {
+      if (ARG1 >= VG_(fd_soft_limit) ||
+          ARG1 == VG_(log_output_sink).fd ||
+          ARG1 == VG_(xml_output_sink).fd) {
+         SET_STATUS_Failure (VKI_EBADF);
+      }
+   } else if (!ML_(fd_allowed)(ARG1, "fcntl", tid, False)) {
      SET_STATUS_Failure (VKI_EBADF);
    }
 }
@@ -7563,8 +7572,17 @@ PRE(sys_fcntl64)
 #  endif
       *flags |= SfMayBlock;
 
-   if (!ML_(fd_allowed)(ARG1, "fcntl64", tid, False)) {
-     SET_STATUS_Failure (VKI_EBADF);
+   /* F_GETFD is used to check if a file descriptor is valid, so only
+      make sure it isn't a valgrind fd, otherwise we might warn, with
+      --track-fds=bad for any bad fd.  */
+   if (ARG2 == VKI_F_GETFD) {
+      if (ARG1 >= VG_(fd_soft_limit) ||
+          ARG1 == VG_(log_output_sink).fd ||
+          ARG1 == VG_(xml_output_sink).fd) {
+         SET_STATUS_Failure (VKI_EBADF);
+      }
+   } else if (!ML_(fd_allowed)(ARG1, "fcntl64", tid, False)) {
+      SET_STATUS_Failure (VKI_EBADF);
    }
 }