You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
comment match mangles comment if it contains a ' character #240
void xtables_save_string(const char *value)
{
static const char no_quote_chars[] = "_-0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const char escape_chars[] = "\"\\'";
size_t length;
const char *p;
length = strspn(value, no_quote_chars);
if (length > 0 && value[length] == 0) {
/* no quoting required */
putchar(' ');
fputs(value, stdout);
} else {
/* there is at least one dangerous character in the
value, which we have to quote. Write double quotes
around the value and escape special characters with
a backslash */
printf(" \"");
for (p = strpbrk(value, escape_chars); p != NULL;
p = strpbrk(value, escape_chars)) {
if (p > value)
fwrite(value, 1, p - value, stdout);
putchar('\\');
putchar(*p);
value = p + 1;
}
/* print the rest and finish the double quoted
string */
fputs(value, stdout);
putchar('\"');
}
}
It quotes the characters ", \ and '. Let me think about a workaround here.
Activity
ldx commentedon May 24, 2018
The problem seems to be in the native library:
It quotes the characters
",\and'. Let me think about a workaround here.Workaround iptables save() quoting issue
ldx commentedon May 24, 2018
I pushed a commit with a workaround. Feel free to give it a shot, though I'm still thinking whether this is the right way to work around the issue.
multun commentedon Oct 22, 2018
Parsing also fails when the comment contains an exclamation mark. How about using shlex instead of a regex ?
ldx commentedon Oct 23, 2018
@multun do you mean when parsing the output from save()?
multun commentedon Oct 26, 2018
@ldx yup
python-iptables/iptc/ip4tc.py
Line 392 in e42e691