diff options
author | Max Kellermann <max@duempel.org> | 2008-01-29 13:45:29 +0000 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2008-01-29 13:45:29 +0000 |
commit | 3bf54dffc605c88f10b0937c5e3e980328b64b72 (patch) | |
tree | bcdbcd512c9499bc7e411568aff1296931230443 /iptables-restore.c | |
parent | a5d099400fd6f9ad3880dda10f85d2aa36b5ec65 (diff) |
unescape parameters
Max Kellermann <max@duempel.org>
Diffstat (limited to 'iptables-restore.c')
-rw-r--r-- | iptables-restore.c | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/iptables-restore.c b/iptables-restore.c index ade1a2fe..2522b0f5 100644 --- a/iptables-restore.c +++ b/iptables-restore.c @@ -319,7 +319,7 @@ main(int argc, char *argv[]) /* the parser */ char *curchar; - int quote_open; + int quote_open, escaped; size_t param_len; /* reset the newargv */ @@ -367,34 +367,39 @@ main(int argc, char *argv[]) * longer a real hacker, but I can live with that */ quote_open = 0; + escaped = 0; param_len = 0; for (curchar = parsestart; *curchar; curchar++) { char param_buffer[1024]; - 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 (escaped) { + param_buffer[param_len++] = *curchar; + escaped = 0; + continue; + } + + if (quote_open) { + if (*curchar == '\\') { + escaped = 1; + continue; + } else if (*curchar == '"') { quote_open = 0; *curchar = ' '; - } else if (!quote_open) { + } else { + param_buffer[param_len++] = *curchar; + continue; + } + } else { + if (*curchar == '"') { quote_open = 1; continue; } - } + } + if (*curchar == ' ' || *curchar == '\t' || * curchar == '\n') { - - if (quote_open) { - param_buffer[param_len++] = - *curchar; - continue; - } - if (!param_len) { /* two spaces? */ continue; @@ -414,18 +419,6 @@ main(int argc, char *argv[]) add_argv(param_buffer); param_len = 0; } else { - /* Skip backslash that escapes quote: - * the standard input does not require - * escaping. However, the output - * generated by iptables-save - * introduces bashlash to keep - * consistent with iptables - */ - if (quote_open && - *curchar == '\\' && - *(curchar+1) == '"') - continue; - /* regular character, copy to buffer */ param_buffer[param_len++] = *curchar; |