Skip to contentSkip to conversation

fix iptables-restore escaping of quotes

PATCH New Philip Craig 1 participant 1 message Dec 20, 2004 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix iptables-restore escaping of quotes

iptables-restore was losing a character at the start of the parameter for every escaped quote within the parameter.

This is of signifance when there are " characters in log prefixes. Note that iptables-save can't generate escaped quotes; I am generating the input for iptables-restore from a script.

Signature · 1 line
Philip Craig - SnapGear, A CyberGuard Company - http://www.SnapGear.com
iptables-restore.c +8 -5
Index: iptables-restore.c
===================================================================
@@ -336,12 +336,15 @@
 			param_start = parsestart;
 			
 			for (curchar = parsestart; *curchar; curchar++) {
+				if (*curchar == '\\' && *(curchar+1) == '"') {
+					if (quote_open) {
+						memmove(curchar, curchar+1,
+							strlen(curchar+1));
+						continue;
+					}
+				}
 				if (*curchar == '"') {
-					/* quote_open cannot be true if there
-					 * was no previous character.  Thus, 
-					 * curchar-1 has to be within bounds */
-					if (quote_open && 
-					    *(curchar-1) != '\\') {
+					if (quote_open) {
 						quote_open = 0;
 						*curchar = ' ';
 					} else {