]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus: Fix writing off the end of an fd_set when testing with Valgrind
authorPhilip Withnall <withnall@endlessm.com>
Wed, 22 Feb 2017 10:56:56 +0000 (10:56 +0000)
committerSimon McVittie <smcv@collabora.com>
Fri, 7 Apr 2017 11:52:34 +0000 (12:52 +0100)
If the test-bus test is run under Valgrind, its code to detect FD leaks
accidentally writes off the end of the fd_set it uses, as Valgrind opens
some high FDs (≥1024) for internal use.

Ignore those FDs. Realistically, they are never going to be leaks — in
order to have a false negative from omitting this check, D-Bus would
have to allocate and not leak all the FDs up to FD_SETSIZE, and then
leak the first FD over that which it allocated. D-Bus never allocates
anywhere near that number of FDs concurrently.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99839

dbus/dbus-message-util.c

index 9fa5a21cb3c4751d7e271faac6c011814b602cc3..bedf6b4f8016c1c29f66e7cf64da9c21f6e1dc89 100644 (file)
@@ -182,6 +182,13 @@ _dbus_check_fdleaks_enter (void)
           if (fd == dirfd (d))
             continue;
 
+          if (fd >= FD_SETSIZE)
+            {
+              _dbus_verbose ("FD %d unexpectedly large; cannot track whether "
+                             "it is leaked\n", fd);
+              continue;
+            }
+
           FD_SET (fd, &fds->set);
         }
 
@@ -227,6 +234,13 @@ _dbus_check_fdleaks_leave (DBusInitialFDs *fds)
           if (fd == dirfd (d))
             continue;
 
+          if (fd >= FD_SETSIZE)
+            {
+              _dbus_verbose ("FD %d unexpectedly large; cannot track whether "
+                             "it is leaked\n", fd);
+              continue;
+            }
+
           if (FD_ISSET (fd, &fds->set))
             continue;