tevent: Fix a segfault upon the first signal
authorVolker Lendecke <vl@samba.org>
Sat, 29 Aug 2009 07:41:32 +0000 (09:41 +0200)
committerVolker Lendecke <vl@samba.org>
Sat, 29 Aug 2009 07:49:08 +0000 (09:49 +0200)
When the first signal arrives, tevent_common_signal_handler() crashed: "ev" is
initialized to NULL, so the first "write(ev->pipe_fds[1], &c, 1);" dereferences
NULL.

Rusty, Tridge, please check. Also, can you tell me a bit more about the
environment you tested this in? I'd be curious to see where this survived.

Thanks,

Volker

lib/tevent/tevent_signal.c

index 0333325ef0f3de3a3fcd39aac5e7ff6368b505e3..b329f8c1e72ca73045f2f5abb5315c7373572fb6 100644 (file)
@@ -85,6 +85,12 @@ static void tevent_common_signal_handler(int signum)
        SIG_INCREMENT(sig_state->signal_count[signum]);
        SIG_INCREMENT(sig_state->got_signal);
 
+       if (sig_state->sig_handlers[signum] != NULL) {
+               ev = sig_state->sig_handlers[signum]->se->event_ctx;
+               /* doesn't matter if this pipe overflows */
+               res = write(ev->pipe_fds[1], &c, 1);
+       }
+
        /* Write to each unique event context. */
        for (sl = sig_state->sig_handlers[signum]; sl; sl = sl->next) {
                if (sl->se->event_ctx != ev) {