From: Philip Withnall Date: Thu, 22 Jan 2015 20:11:07 +0000 (+0000) Subject: dbus-socket-set-epoll: initialize all bytes of struct epoll_event X-Git-Tag: dbus-1.11.12~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e411f221579b9a8643bd456b624bd3e219b44b83;p=thirdparty%2Fdbus.git dbus-socket-set-epoll: initialize all bytes of struct epoll_event This should be a no-op, but it shuts Valgrind up. The reason for the warning is that we fill in event.events and event.data.fd, but the union event.data actually contains more bytes than that. We'll get the same partially initialized union back from the kernel in socket_set_epoll_poll(), where we take events[i].data.fd and ignore the rest. So the current code is safe, but valgrind is right to worry. This is an expanded version of an older patch by Simon McVittie. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88808 Signed-off-by: Simon McVittie --- diff --git a/dbus/dbus-socket-set-epoll.c b/dbus/dbus-socket-set-epoll.c index 5bd8d5a09..4692cbe45 100644 --- a/dbus/dbus-socket-set-epoll.c +++ b/dbus/dbus-socket-set-epoll.c @@ -144,6 +144,7 @@ socket_set_epoll_add (DBusSocketSet *set, struct epoll_event event; int err; + _DBUS_ZERO (event); event.data.fd = fd; if (enabled) @@ -196,6 +197,7 @@ socket_set_epoll_enable (DBusSocketSet *set, struct epoll_event event; int err; + _DBUS_ZERO (event); event.data.fd = fd; event.events = watch_flags_to_epoll_events (flags); @@ -251,6 +253,7 @@ socket_set_epoll_disable (DBusSocketSet *set, * work on 2.6.32). Compile this file with -DTEST_BEHAVIOUR_OF_EPOLLET for * test code. */ + _DBUS_ZERO (event); event.data.fd = fd; event.events = EPOLLET; @@ -270,7 +273,8 @@ socket_set_epoll_remove (DBusSocketSet *set, int err; /* Kernels < 2.6.9 require a non-NULL struct pointer, even though its * contents are ignored */ - struct epoll_event dummy = { 0 }; + struct epoll_event dummy; + _DBUS_ZERO (dummy); if (epoll_ctl (self->epfd, EPOLL_CTL_DEL, fd, &dummy) == 0) return; @@ -346,6 +350,8 @@ main (void) int fd = 0; /* stdin */ int ret; + _DBUS_ZERO (input); + input.events = EPOLLHUP | EPOLLET; ret = epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &input); printf ("ctl ADD: %d\n", ret);