[dovecot-cvs] dovecot/src/lib-auth auth-client.c, 1.7, 1.8 auth-client.h, 1.11, 1.12 auth-server-connection.c, 1.15, 1.16 auth-server-connection.h, 1.9, 1.10 auth-server-request.c, 1.24, 1.25

cras at dovecot.org cras at dovecot.org
Sat Jan 14 20:47:25 EET 2006


Update of /var/lib/cvs/dovecot/src/lib-auth
In directory talvi:/tmp/cvs-serv16037/lib-auth

Modified Files:
	auth-client.c auth-client.h auth-server-connection.c 
	auth-server-connection.h auth-server-request.c 
Log Message:
deinit, unref, destroy, close, free, etc. functions now take a pointer to
their data pointer, and set it to NULL. This makes double-frees less likely
to cause security holes.



Index: auth-client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-auth/auth-client.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- auth-client.c	13 Jan 2006 20:26:03 -0000	1.7
+++ auth-client.c	14 Jan 2006 18:47:23 -0000	1.8
@@ -34,12 +34,15 @@
 	return client;
 }
 
-void auth_client_free(struct auth_client *client)
+void auth_client_free(struct auth_client **_client)
 {
+	struct auth_client *client = *_client;
 	struct auth_server_connection *next;
 	struct auth_mech_desc *mech;
 	size_t i, size;
 
+	*_client = NULL;
+
 	mech = buffer_get_modifyable_data(client->available_auth_mechs, &size);
 	size /= sizeof(*mech);
 	for (i = 0; i < size; i++)
@@ -48,12 +51,12 @@
 
 	while (client->connections != NULL) {
 		next = client->connections->next;
-		auth_server_connection_destroy(client->connections, FALSE);
+		auth_server_connection_destroy(&client->connections, FALSE);
 		client->connections = next;
 	}
 
 	if (client->to_reconnect != NULL)
-		timeout_remove(client->to_reconnect);
+		timeout_remove(&client->to_reconnect);
 	i_free(client->socket_paths);
 	i_free(client);
 }
@@ -189,10 +192,8 @@
 			client->to_reconnect =
 				timeout_add(5000, reconnect_timeout, client);
 		}
-	} else if (client->to_reconnect != NULL) {
-		timeout_remove(client->to_reconnect);
-		client->to_reconnect = NULL;
-	}
+	} else if (client->to_reconnect != NULL)
+		timeout_remove(&client->to_reconnect);
 
 	if (client->connect_notify_callback != NULL) {
 		client->connect_notify_callback(client,

Index: auth-client.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-auth/auth-client.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- auth-client.h	13 Jan 2006 20:26:03 -0000	1.11
+++ auth-client.h	14 Jan 2006 18:47:23 -0000	1.12
@@ -42,7 +42,7 @@
 
 /* Create new authentication client. */
 struct auth_client *auth_client_new(unsigned int client_pid);
-void auth_client_free(struct auth_client *client);
+void auth_client_free(struct auth_client **client);
 
 bool auth_client_is_connected(struct auth_client *client);
 void auth_client_set_connect_notify(struct auth_client *client,

Index: auth-server-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-auth/auth-server-connection.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- auth-server-connection.c	13 Jan 2006 20:26:03 -0000	1.15
+++ auth-server-connection.c	14 Jan 2006 18:47:23 -0000	1.16
@@ -135,13 +135,13 @@
 		return;
 	case -1:
 		/* disconnected */
-		auth_server_connection_destroy(conn, TRUE);
+		auth_server_connection_destroy(&conn, TRUE);
 		return;
 	case -2:
 		/* buffer full - can't happen unless auth is buggy */
 		i_error("BUG: Auth server sent us more than %d bytes of data",
 			AUTH_CLIENT_MAX_LINE_LENGTH);
-		auth_server_connection_destroy(conn, FALSE);
+		auth_server_connection_destroy(&conn, FALSE);
 		return;
 	}
 
@@ -156,7 +156,7 @@
 		    AUTH_CLIENT_PROTOCOL_MAJOR_VERSION) {
 			i_error("Authentication server not compatible with "
 				"this client (mixed old and new binaries?)");
-			auth_server_connection_destroy(conn, FALSE);
+			auth_server_connection_destroy(&conn, FALSE);
 			return;
 		}
 		conn->version_received = TRUE;
@@ -184,7 +184,7 @@
 		}
 
 		if (!ret) {
-			auth_server_connection_destroy(conn, FALSE);
+			auth_server_connection_destroy(&conn, FALSE);
 			break;
 		}
 	}
@@ -249,18 +249,21 @@
 	if (o_stream_send_str(conn->output, handshake) < 0) {
 		errno = conn->output->stream_errno;
 		i_warning("Error sending handshake to auth server: %m");
-		auth_server_connection_destroy(conn, TRUE);
+		auth_server_connection_destroy(&conn, TRUE);
 		return NULL;
 	}
 	return conn;
 }
 
-void auth_server_connection_destroy(struct auth_server_connection *conn,
+void auth_server_connection_destroy(struct auth_server_connection **_conn,
 				    bool reconnect)
 {
+        struct auth_server_connection *conn = *_conn;
 	struct auth_client *client = conn->client;
 	struct auth_server_connection **pos;
 
+	*_conn = NULL;
+
 	if (conn->fd == -1)
 		return;
 
@@ -279,10 +282,8 @@
 		client->ext_input_remove(conn->ext_input_io);
 		conn->ext_input_io = NULL;
 	}
-	if (conn->io != NULL) {
-		io_remove(conn->io);
-		conn->io = NULL;
-	}
+	if (conn->io != NULL)
+		io_remove(&conn->io);
 
 	i_stream_close(conn->input);
 	o_stream_close(conn->output);
@@ -312,8 +313,8 @@
 	hash_destroy(conn->requests);
 	buffer_free(conn->auth_mechs_buf);
 
-	i_stream_unref(conn->input);
-	o_stream_unref(conn->output);
+	i_stream_unref(&conn->input);
+	o_stream_unref(&conn->output);
 	pool_unref(conn->pool);
 }
 

Index: auth-server-connection.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-auth/auth-server-connection.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- auth-server-connection.h	13 Jan 2006 20:26:03 -0000	1.9
+++ auth-server-connection.h	14 Jan 2006 18:47:23 -0000	1.10
@@ -54,7 +54,7 @@
 
 struct auth_server_connection *
 auth_server_connection_new(struct auth_client *client, const char *path);
-void auth_server_connection_destroy(struct auth_server_connection *conn,
+void auth_server_connection_destroy(struct auth_server_connection **conn,
 				    bool reconnect);
 
 struct auth_server_connection *

Index: auth-server-request.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-auth/auth-server-request.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- auth-server-request.c	13 Jan 2006 20:26:03 -0000	1.24
+++ auth-server-request.c	14 Jan 2006 18:47:23 -0000	1.25
@@ -117,7 +117,7 @@
 	if (ret < 0) {
 		errno = conn->output->stream_errno;
 		i_warning("Error sending request to auth server: %m");
-		auth_server_connection_destroy(conn, TRUE);
+		auth_server_connection_destroy(&conn, TRUE);
 		return FALSE;
 	}
 
@@ -144,7 +144,7 @@
 	if (o_stream_sendv(conn->output, iov, 3) < 0) {
 		errno = conn->output->stream_errno;
 		i_warning("Error sending continue request to auth server: %m");
-		auth_server_connection_destroy(conn, TRUE);
+		auth_server_connection_destroy(&conn, TRUE);
 	}
 }
 



More information about the dovecot-cvs mailing list