changeset 1192:48759e3f7611

Reject more quickly invalid messages if possible
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 11 Jun 2013 10:05:50 +0800
parents 60e7b02a3ce7
children dcc467aeda12
files libfdcore/cnxctx.c libfdcore/server.c
diffstat 2 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libfdcore/cnxctx.c	Tue Jun 11 09:18:52 2013 +0800
+++ b/libfdcore/cnxctx.c	Tue Jun 11 10:05:50 2013 +0800
@@ -807,6 +807,9 @@
 			}
 
 			received += ret;
+			
+			if (header[0] != DIAMETER_VERSION)
+				break; /* No need to wait for 4 bytes in this case */
 		} while (received < sizeof(header));
 
 		rcv_data.length = ((size_t)header[1] << 16) + ((size_t)header[2] << 8) + (size_t)header[3];
--- a/libfdcore/server.c	Tue Jun 11 09:18:52 2013 +0800
+++ b/libfdcore/server.c	Tue Jun 11 10:05:50 2013 +0800
@@ -154,6 +154,8 @@
 next_client:
 	LOG_A("Ready to process next incoming connection");
 
+	memset(&rcv_data, 0, sizeof(rcv_data));
+	
 	/* Get the next connection */
 	CHECK_FCT_DO( fd_fifo_get( s->pending, &c ), { fatal = 1; goto cleanup; } );
 
@@ -178,8 +180,6 @@
 	CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), { fatal = 1; goto cleanup; } );
 	ts.tv_sec += INCNX_TIMEOUT;
 	
-	memset(&rcv_data, 0, sizeof(rcv_data));
-	
 	/* Receive the first Diameter message on the connection -- cleanup in case of timeout */
 	CHECK_FCT_DO( fd_cnx_receive(c, &ts, &rcv_data.buffer, &rcv_data.length), 
 		{
"Welcome to our mercurial repository"