git » nmdb » commit 646fd0f

Fix minimum message size checks.

author Alberto Bertogli
2007-10-11 07:32:47 UTC
committer Alberto Bertogli
2007-10-11 07:32:47 UTC
parent 00e67abb6b27389beccfdffc4ac123713fc982bc

Fix minimum message size checks.

The checks for all the protocols were wrong: SCTP, TIPC and UDP had it too
low (2 bytes), and TCP too big (12 bytes).

The minimum message size is 8 (4 version + ID, 4 command).

We never catched the TCP problem until now because all commands had
payloads and were >= 12 bytes.

Signed-off-by: Alberto Bertogli <albertito@gmail.com>

nmdb/sctp.c +1 -1
nmdb/tcp.c +1 -1
nmdb/tipc.c +1 -1
nmdb/udp.c +1 -1

diff --git a/nmdb/sctp.c b/nmdb/sctp.c
index 7b02da3..bd74037 100644
--- a/nmdb/sctp.c
+++ b/nmdb/sctp.c
@@ -212,7 +212,7 @@ void sctp_recv(int fd, short event, void *arg)
 		goto exit;
 	}
 
-	if (rv < 2) {
+	if (rv < 8) {
 		stats.net_broken_req++;
 		goto exit;
 	}
diff --git a/nmdb/tcp.c b/nmdb/tcp.c
index e511087..c1ed546 100644
--- a/nmdb/tcp.c
+++ b/nmdb/tcp.c
@@ -379,7 +379,7 @@ static void process_buf(struct tcp_socket *tcpsock,
 	if (len >= 4) {
 		totaltoget = * (uint32_t *) buf;
 		totaltoget = ntohl(totaltoget);
-		if (totaltoget > (64 * 1024) || totaltoget <= 12) {
+		if (totaltoget > (64 * 1024) || totaltoget <= 8) {
 			/* Message too big or too small, close the connection. */
 			goto error_exit;
 		}
diff --git a/nmdb/tipc.c b/nmdb/tipc.c
index c821120..9d35a7f 100644
--- a/nmdb/tipc.c
+++ b/nmdb/tipc.c
@@ -196,7 +196,7 @@ void tipc_recv(int fd, short event, void *arg)
 		goto exit;
 	}
 
-	if (rv < 2) {
+	if (rv < 8) {
 		stats.net_broken_req++;
 		goto exit;
 	}
diff --git a/nmdb/udp.c b/nmdb/udp.c
index 2adf54f..edf85b4 100644
--- a/nmdb/udp.c
+++ b/nmdb/udp.c
@@ -196,7 +196,7 @@ void udp_recv(int fd, short event, void *arg)
 		goto exit;
 	}
 
-	if (rv < 2) {
+	if (rv < 8) {
 		stats.net_broken_req++;
 		goto exit;
 	}