messaging: Avoid crashes
authorVolker Lendecke <vl@samba.org>
Fri, 30 Sep 2016 13:42:40 +0000 (06:42 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 5 Oct 2016 01:51:43 +0000 (03:51 +0200)
With the latest patches we defer messages to a messaging_context's default
context, the one that it was created with. This is another incarnation of
085542fc93b3 (I believe): messaging contexts can outlive their tevent contexts.

In this case, the tevent_schedule_immediate(msg_ctx->event_ctx) has nothing to
schedule on and will crash. This patch uses the fact that tevent_fd's can
outlive their event_contexts. When the tevent_context dies, all tevent_fd's
will get their flags set to 0. The tevent_handles in messages_dgm_ref always
have TEVENT_FD_READ set, so a 0 flags field indicates the tevent_context has
died.

Signed-off-by: Volker Lendecke <vl@samba.org>
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Oct  5 03:51:43 CEST 2016 on sn-devel-144

source3/lib/messages_dgm_ref.c

index a81e25f377c78fe7c9a994f55d9e3a7a405d725a..bc6b69fb62ed988dad33f93235e734b59c995b20 100644 (file)
@@ -129,7 +129,18 @@ static void msg_dgm_ref_recv(struct tevent_context *ev,
         * that grabs the fd's will get them.
         */
        for (r = refs; r != NULL; r = next) {
+               uint16_t flags;
+
                next = r->next;
+
+               flags = tevent_fd_get_flags(r->tevent_handle);
+               if (flags == 0) {
+                       /*
+                        * r's tevent_context has died.
+                        */
+                       continue;
+               }
+
                r->recv_cb(ev, msg, msg_len, fds, num_fds,
                           r->recv_cb_private_data);
        }