]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables: use strspn() to check if string needs to be quoted
authorMax Kellerman <max@duempel.org>
Thu, 17 Feb 2011 10:57:19 +0000 (11:57 +0100)
committerPatrick McHardy <kaber@trash.net>
Thu, 17 Feb 2011 10:57:19 +0000 (11:57 +0100)
Problem: the call xtables_save_string("'") prints just a single quote,
not enclosed in double quoted and not escaped.

Steps to reproduce:

 $ iptables -A foo -m comment --comment "'" -j ACCEPT
 $ iptables-multi save|grep foo
 -A foo -m comment --comment ' -j ACCEPT

The cause was the use of strcspn() to locate the first character which
justified quoting the string in double quotes.  That however was
wrong, because the way strcspn() was called, it returned a pointer to
the first character that was not to be escaped, which did the right
thing most of the time, but not for strings consisting only of quote
characters.  This patch changes strcspn() to strspn().

Signed-off-by: Patrick McHardy <kaber@trash.net>
xtables.c

index fc59f753ef784b975fd8a7803f7bf845b483c55a..57d5d13e8e1c6f4c362d551050f455c1d5c1378d 100644 (file)
--- a/xtables.c
+++ b/xtables.c
@@ -1638,7 +1638,7 @@ void xtables_save_string(const char *value)
        size_t length;
        const char *p;
 
-       length = strcspn(value, no_quote_chars);
+       length = strspn(value, no_quote_chars);
        if (length > 0 && value[length] == 0) {
                /* no quoting required */
                putchar(' ');