netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xtables: use strspn() to check if string needs to be quoted
@ 2011-02-14  6:54 Max Kellermann
  2011-02-17 11:00 ` Patrick McHardy
  0 siblings, 1 reply; 2+ messages in thread
From: Max Kellermann @ 2011-02-14  6:54 UTC (permalink / raw)
  To: netfilter-devel

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().
---
 xtables.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/xtables.c b/xtables.c
index fc59f75..57d5d13 100644
--- 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(' ');


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

* Re: [PATCH] xtables: use strspn() to check if string needs to be quoted
  2011-02-14  6:54 [PATCH] xtables: use strspn() to check if string needs to be quoted Max Kellermann
@ 2011-02-17 11:00 ` Patrick McHardy
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick McHardy @ 2011-02-17 11:00 UTC (permalink / raw)
  To: Max Kellermann; +Cc: netfilter-devel

Am 14.02.2011 07:54, schrieb Max Kellermann:
> 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().

Looks good to me, applied. But please remember to sign off your
patches.


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

end of thread, other threads:[~2011-02-17 11:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-14  6:54 [PATCH] xtables: use strspn() to check if string needs to be quoted Max Kellermann
2011-02-17 11:00 ` Patrick McHardy

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).