dovecot-2.0: auth: Don't assert-crash if a request still succeed...

dovecot at dovecot.org dovecot at dovecot.org
Thu Sep 30 19:49:49 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/bc782780d0fe
changeset: 12212:bc782780d0fe
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 30 17:49:17 2010 +0100
description:
auth: Don't assert-crash if a request still succeeds after its client connection is gone.

diffstat:

 src/auth/auth-client-connection.c |   2 +-
 src/auth/auth-request-handler.c   |  25 ++++++++++++++++++++++++-
 src/auth/auth-request-handler.h   |   1 +
 3 files changed, 26 insertions(+), 2 deletions(-)

diffs (82 lines):

diff -r dfa2b49d8298 -r bc782780d0fe src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c	Thu Sep 30 17:12:55 2010 +0100
+++ b/src/auth/auth-client-connection.c	Thu Sep 30 17:49:17 2010 +0100
@@ -352,7 +352,7 @@
 	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 -r dfa2b49d8298 -r bc782780d0fe src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c	Thu Sep 30 17:12:55 2010 +0100
+++ b/src/auth/auth-request-handler.c	Thu Sep 30 17:49:17 2010 +0100
@@ -29,6 +29,8 @@
 	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 @@
 	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 @@
 	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 @@
 	unsigned int id;
 	buffer_t *buf;
 
+	i_assert(!handler->destroyed);
+
 	/* <id> <mechanism> [...] */
 	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 -r dfa2b49d8298 -r bc782780d0fe src/auth/auth-request-handler.h
--- a/src/auth/auth-request-handler.h	Thu Sep 30 17:12:55 2010 +0100
+++ b/src/auth/auth-request-handler.h	Thu Sep 30 17:49:17 2010 +0100
@@ -29,6 +29,7 @@
 		(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);
 


More information about the dovecot-cvs mailing list