[PATCH] nfsim TCP related fixes

Jozsef Kadlecsik kadlec at blackhole.kfki.hu
Mon Feb 21 09:07:05 CET 2005


Hi,

I discovered two TCP related bugs in gen_ip: TCP SEQ and ACK numbers were
converted from string to u_int16_t instead of u_int32_t and full length
TCP options could not be specified.

The attached patch fixes both, please review and apply.

Best regards,
Jozsef
-
E-mail  : kadlec at blackhole.kfki.hu, kadlec at sunserv.kfki.hu
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
          H-1525 Budapest 114, POB. 49, Hungary
-------------- next part --------------
diff -urN --exclude-from=/usr/src/diff.exclude nfsim.orig/tools/gen_ip.c nfsim/tools/gen_ip.c
--- nfsim.orig/tools/gen_ip.c	2005-01-19 14:06:32.000000000 +0100
+++ nfsim/tools/gen_ip.c	2005-02-19 17:35:10.000000000 +0100
@@ -73,6 +73,24 @@
 		return -1;
 }
 
+static unsigned long int 
+string_to_ulong(const char *s, unsigned long int min, unsigned long int max)
+{
+	unsigned long int number;
+	char *end;
+
+	/* Handle hex, octal, etc. */
+	number = strtoul(s, &end, 0);
+	if (*end == '\0' && end != s) {
+		/* we parsed a number, let's see if we want this */
+		if (min <= number && number <= max)
+			return number;
+		else
+			return -1;
+	} else
+		return -1;
+}
+
 /* static u_int16_t*/
 static int
 parse_protocol(const char *s)
@@ -394,11 +412,13 @@
 	size_t i;
 
 	/* Options are simple comma-separated number list. */
-	for (i = 0, tok=strtok(opts, ","); tok; tok=strtok(NULL, ","), i++)
+	for (i = 0, tok=strtok(opts, ","); 
+	     tok && i < sizeof(options);
+	     tok=strtok(NULL, ","), i++)
 		options[i] = atol(tok);
 
-	if (i >= sizeof(options)) {
-		nfsim_log(LOG_UI, "Too many TCP options `%s'", opts);
+	if (tok) {
+		nfsim_log(LOG_UI, "Too many TCP options: %s", opts);
 		return 1;
 	}
 	if (i % 4 != 0) {
@@ -413,9 +433,9 @@
 static int
 parse_tcpnumber(const char *number, u_int32_t *val)
 {
-	int i;
+	unsigned long int i;
 
-	i = string_to_number(number, 0, INT_MAX);
+	i = string_to_ulong(number, 0, ULONG_MAX);
 	if (i < 0) {
 		nfsim_log(LOG_UI, "Invalid tcp number `%s'", number);
 		return 1;


More information about the netfilter-devel mailing list