about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2011-01-23 15:14:18 +0100
committerAlexander Barton <alex@barton.de>2011-01-23 15:14:18 +0100
commit765dc320f11f117d63e5285a903dfe8af4a48795 (patch)
treea95d0b89edfcacd3cd49b76e758986c04e34dfbb /src
parent9fff9f6a2b1f113513b95eae3eaa3c55052f8b91 (diff)
downloadngircd-765dc320f11f117d63e5285a903dfe8af4a48795.tar.gz
ngircd-765dc320f11f117d63e5285a903dfe8af4a48795.zip
Read_Request(): don't access possibly free'd CLIENT structure
Handle_Buffer() can shut down connections and remove clients, so after
calling it, we have to make sure that our CLIENT pointer is still valid.
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/conn.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 98a05434..af79c13f 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -1455,16 +1455,21 @@ Read_Request( CONN_ID Idx )
 
 	/* Update connection statistics */
 	My_Connections[Idx].bytes_in += len;
+	My_Connections[Idx].bps += Handle_Buffer(Idx);
+
+	/* Make sure that there is still a valid client registered */
+	c = Conn_GetClient(Idx);
+	if (!c)
+		return;
 
 	/* Update timestamp of last data received if this connection is
 	 * registered as a user, server or service connection. Don't update
 	 * otherwise, so users have at least Conf_PongTimeout seconds time to
 	 * register with the IRC server -- see Check_Connections().
 	 * Update "lastping", too, if time shifted backwards ... */
-	c = Conn_GetClient(Idx);
-	if (c && (Client_Type(c) == CLIENT_USER
-		  || Client_Type(c) == CLIENT_SERVER
-		  || Client_Type(c) == CLIENT_SERVICE)) {
+	if (Client_Type(c) == CLIENT_USER
+	    || Client_Type(c) == CLIENT_SERVER
+	    || Client_Type(c) == CLIENT_SERVICE) {
 		t = time(NULL);
 		if (My_Connections[Idx].lastdata != t)
 			My_Connections[Idx].bps = 0;
@@ -1475,7 +1480,6 @@ Read_Request( CONN_ID Idx )
 	}
 
 	/* Look at the data in the (read-) buffer of this connection */
-	My_Connections[Idx].bps += Handle_Buffer(Idx);
 	if (Client_Type(c) != CLIENT_SERVER
 	    && Client_Type(c) != CLIENT_UNKNOWNSERVER
 	    && Client_Type(c) != CLIENT_SERVICE