netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* iproute2/m_ipt fix, opts was not set properly
@ 2008-08-05 19:24 Denys Fedoryshchenko
  2008-08-06  9:52 ` jamal
  0 siblings, 1 reply; 7+ messages in thread
From: Denys Fedoryshchenko @ 2008-08-05 19:24 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

[-- Attachment #1: Type: text/plain, Size: 433 bytes --]

Since opts global variable, if it is set to original_opts, it was done in 
local context of function, and global variable in result was pointing to 
freed memory. Sure result of that - segfault, it is possible to trigger it 
only while processing batch, cause only on next iteration opts was wrong.

There is two ways to fix that, both patches attached.
Please send me note, which way correct (at least i will learn something :-) )


[-- Attachment #2: ipt_m_v1.patch --]
[-- Type: text/x-diff, Size: 805 bytes --]

diff -Naur iproute2-original/tc/m_ipt.c iproute2-patched/tc/m_ipt.c
--- iproute2-original/tc/m_ipt.c	2008-08-05 19:15:56.000000000 +0000
+++ iproute2-patched/tc/m_ipt.c	2008-08-05 19:20:20.000000000 +0000
@@ -162,7 +162,7 @@
 	return result;
 }
 
-static void free_opts(struct option *opts)
+static void free_opts(void)
 {
 	if (opts != original_opts) {
 		free(opts);
@@ -455,7 +455,7 @@
 		if (matches(argv[optind], "index") == 0) {
 			if (get_u32(&index, argv[optind + 1], 10)) {
 				fprintf(stderr, "Illegal \"index\"\n");
-				free_opts(opts);
+				free_opts();
 				return -1;
 			}
 			iok++;
@@ -513,7 +513,7 @@
 	*argv_p = argv;
 
 	optind = 1;
-	free_opts(opts);
+	free_opts();
 
 	return 0;
 
@@ -594,7 +594,7 @@
 		fprintf(f, " \n");
 
 	}
-	free_opts(opts);
+	free_opts();
 
 	return 0;
 }

[-- Attachment #3: ipt_m_v2.patch --]
[-- Type: text/x-diff, Size: 510 bytes --]

diff -Naur iproute2-original/tc/m_ipt.c iproute2-patched2/tc/m_ipt.c
--- iproute2-original/tc/m_ipt.c	2008-08-05 19:15:56.000000000 +0000
+++ iproute2-patched2/tc/m_ipt.c	2008-08-05 19:22:55.000000000 +0000
@@ -162,10 +162,10 @@
 	return result;
 }
 
-static void free_opts(struct option *opts)
+static void free_opts(struct option *opts_local)
 {
-	if (opts != original_opts) {
-		free(opts);
+	if (opts_local != original_opts) {
+		free(opts_local);
 		opts = original_opts;
 		global_option_offset = 0;
 	}

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-08-06 11:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-05 19:24 iproute2/m_ipt fix, opts was not set properly Denys Fedoryshchenko
2008-08-06  9:52 ` jamal
2008-08-06 10:06   ` Denys Fedoryshchenko
2008-08-06 10:42     ` jamal
2008-08-06 10:52       ` jamal
2008-08-06 11:02         ` Denys Fedoryshchenko
2008-08-06 11:18           ` jamal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).