From: Timo Sirainen Date: Thu, 30 Sep 2010 16:49:17 +0000 (+0100) Subject: auth: Don't assert-crash if a request still succeeds after its client connection... X-Git-Tag: 2.0.5~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5363f51ad46344f4e5952f2fef211a7cf8f95ddc;p=thirdparty%2Fdovecot%2Fcore.git auth: Don't assert-crash if a request still succeeds after its client connection is gone. --- diff --git a/src/auth/auth-client-connection.c b/src/auth/auth-client-connection.c index 6ac0b56918..0fd46697fb 100644 --- a/src/auth/auth-client-connection.c +++ b/src/auth/auth-client-connection.c @@ -352,7 +352,7 @@ auth_client_connection_destroy_full(struct auth_client_connection **_conn, if (conn->request_handler != NULL) { if (abort_requests) auth_request_handler_abort_requests(conn->request_handler); - auth_request_handler_unref(&conn->request_handler); + auth_request_handler_destroy(&conn->request_handler); } master_service_client_connection_destroyed(master_service); diff --git a/src/auth/auth-request-handler.c b/src/auth/auth-request-handler.c index c3d5cb0b7c..1354970b8e 100644 --- a/src/auth/auth-request-handler.c +++ b/src/auth/auth-request-handler.c @@ -29,6 +29,8 @@ struct auth_request_handler { void *context; auth_request_callback_t *master_callback; + + unsigned int destroyed:1; }; static ARRAY_DEFINE(auth_failures_arr, struct auth_request *); @@ -103,6 +105,18 @@ void auth_request_handler_unref(struct auth_request_handler **_handler) pool_unref(&handler->pool); } +void auth_request_handler_destroy(struct auth_request_handler **_handler) +{ + struct auth_request_handler *handler = *_handler; + + *_handler = NULL; + + i_assert(!handler->destroyed); + + handler->destroyed = TRUE; + auth_request_handler_unref(&handler); +} + void auth_request_handler_set(struct auth_request_handler *handler, unsigned int connect_uid, unsigned int client_pid) @@ -225,6 +239,13 @@ void auth_request_handler_reply(struct auth_request *request, struct auth_stream_reply *reply; string_t *str; + if (handler->destroyed) { + /* the client connection was already closed. we can't do + anything but abort this request */ + request->internal_failure = TRUE; + result = AUTH_CLIENT_RESULT_FAILURE; + } + reply = auth_stream_reply_init(pool_datastack_create()); switch (result) { case AUTH_CLIENT_RESULT_CONTINUE: @@ -365,10 +386,12 @@ bool auth_request_handler_auth_begin(struct auth_request_handler *handler, unsigned int id; buffer_t *buf; + i_assert(!handler->destroyed); + /* [...] */ list = t_strsplit(args, "\t"); if (list[0] == NULL || list[1] == NULL || - str_to_uint(list[0], &id) < 0) { + str_to_uint(list[0], &id) < 0) { i_error("BUG: Authentication client %u " "sent broken AUTH request", handler->client_pid); return FALSE; diff --git a/src/auth/auth-request-handler.h b/src/auth/auth-request-handler.h index e9bc847fa6..2d751efb1f 100644 --- a/src/auth/auth-request-handler.h +++ b/src/auth/auth-request-handler.h @@ -29,6 +29,7 @@ auth_request_handler_create(auth_request_callback_t *callback, void *context, (auth_request_callback_t *)callback, context, \ master_callback) #endif +void auth_request_handler_destroy(struct auth_request_handler **handler); void auth_request_handler_unref(struct auth_request_handler **handler); void auth_request_handler_abort_requests(struct auth_request_handler *handler);