From 1e7c4519a61f854a7e608a69cfcfc5b5ae681397 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 22 Feb 2017 10:56:56 +0000 Subject: [PATCH] dbus: Fix writing off the end of an fd_set when testing with Valgrind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Detect if it’s running under Valgrind and ignore those FDs; and otherwise assert that the FDs are within the size of an fd_set. Signed-off-by: Philip Withnall https://bugs.freedesktop.org/show_bug.cgi?id=99839 --- dbus/dbus-message-util.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c index 9fa5a21..af340a3 100644 --- a/dbus/dbus-message-util.c +++ b/dbus/dbus-message-util.c @@ -31,6 +31,7 @@ #ifdef HAVE_UNIX_FD_PASSING #include "dbus-sysdeps-unix.h" #endif +#include "dbus-valgrind-internal.h" #ifdef __linux__ /* Necessary for the Linux-specific fd leak checking code only */ @@ -182,6 +183,13 @@ _dbus_check_fdleaks_enter (void) if (fd == dirfd (d)) continue; +#ifdef WITH_VALGRIND + /* Valgrind internally uses some FDs at 1024 and above */ + if (RUNNING_ON_VALGRIND && fd >= FD_SETSIZE) + continue; + _dbus_assert (fd < FD_SETSIZE); +#endif + FD_SET (fd, &fds->set); } @@ -227,6 +235,13 @@ _dbus_check_fdleaks_leave (DBusInitialFDs *fds) if (fd == dirfd (d)) continue; +#ifdef WITH_VALGRIND + /* Valgrind internally uses some FDs at 1024 and above */ + if (RUNNING_ON_VALGRIND && fd >= FD_SETSIZE) + continue; + _dbus_assert (fd < FD_SETSIZE); +#endif + if (FD_ISSET (fd, &fds->set)) continue; -- 2.9.3