From: Oliver <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH 4/6] ipset: Rework the "fake" argument parsing for ipset restore.
Date: Mon, 2 Sep 2013 08:35:55 +0200 [thread overview]
Message-ID: <1378103757-14426-5-git-send-email-oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa> (raw)
In-Reply-To: <1378103757-14426-1-git-send-email-oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
From: Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
This reworks the argument parsing functionality of ipset to handle
quote-delimited lines in such a way that they are considered to be a
single argument.
This commit is necessary for ipset to successfully restore sets that
have comments.
Signed-off-by: Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>
---
src/ipset.c | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/ipset.c b/src/ipset.c
index 4f308da..cff1e55 100644
--- a/src/ipset.c
+++ b/src/ipset.c
@@ -159,20 +159,36 @@ ipset_print_file(const char *fmt, ...)
static void
build_argv(char *buffer)
{
- char *ptr;
+ char *ptr, *tmp;
int i;
/* Reset */
- for (i = 1; i < newargc; i++)
+ for (i = 1; i < newargc; i++) {
+ if(newargv[i])
+ free(newargv[i]);
newargv[i] = NULL;
+ }
newargc = 1;
ptr = strtok(buffer, " \t\r\n");
- newargv[newargc++] = ptr;
+ newargv[newargc] = calloc(strlen(ptr) + 1, sizeof(*ptr));
+ ipset_strlcpy(newargv[newargc++], ptr, strlen(ptr) + 1);
while ((ptr = strtok(NULL, " \t\r\n")) != NULL) {
- if ((newargc + 1) < (int)(sizeof(newargv)/sizeof(char *)))
- newargv[newargc++] = ptr;
- else {
+ if ((newargc + 1) < (int)(sizeof(newargv)/sizeof(char *))) {
+ tmp = newargv[newargc] = calloc(strlen(ptr) + 1, sizeof(*ptr));
+ if(*ptr == '"') {
+ ipset_strlcpy(tmp, ptr + 1, (strlen(ptr) + 1) * sizeof(*ptr));
+ ipset_strlcat(tmp, " ", (strlen(ptr) + 1) * sizeof(*ptr));
+ while((ptr = strtok(NULL, "\"")) != NULL) {
+ if(*ptr == '\n' || *ptr == '\r')
+ continue;
+ tmp = realloc(tmp, (strlen(tmp) + strlen(ptr) + 1) * sizeof(*ptr));
+ ipset_strlcat(tmp, ptr, (strlen(tmp) + strlen(ptr) + 1) * sizeof(*ptr));
+ }
+ } else
+ ipset_strlcpy(tmp, ptr, (strlen(ptr) + 1) * sizeof(*ptr));
+ newargv[newargc++] = tmp;
+ } else {
exit_error(PARAMETER_PROBLEM,
"Line is too long to parse.");
return;
@@ -195,7 +211,8 @@ restore(char *argv0)
/* Initialize newargv/newargc */
newargc = 0;
- newargv[newargc++] = argv0;
+ newargv[newargc] = calloc(strlen(argv0) + 1, sizeof(*argv0));
+ ipset_strlcpy(newargv[newargc++], argv0, strlen(argv0) + 1);
if (filename) {
fd = fopen(filename, "r");
if (!fd) {
@@ -232,6 +249,7 @@ restore(char *argv0)
if (ret < 0)
handle_error();
+ free(newargv[0]);
return ret;
}
--
1.8.3.2
next prev parent reply other threads:[~2013-09-02 6:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-02 6:35 [PATCH 0/6] Ipset comment extension - provide annotation of ipset entries Oliver
2013-09-02 6:35 ` [PATCH 1/6] netfilter: ipset: Support comments for ipset entries in the core Oliver
2013-09-02 8:17 ` Oliver
2013-09-02 8:35 ` Oliver
2013-09-02 6:35 ` [PATCH 2/6] netfilter: ipset: Support comments in hash-type ipsets Oliver
2013-09-02 6:35 ` [PATCH 3/6] netfilter: ipset: Support comments in bitmap-type ipsets Oliver
2013-09-02 6:35 ` Oliver [this message]
2013-09-02 6:35 ` [PATCH 5/6] ipset: Support comments in the userspace library Oliver
2013-09-02 6:35 ` [PATCH 6/6] ipset: Add new userspace set revisions for comment support Oliver
2013-09-02 8:21 ` [PATCH 1/6 v2] netfilter: ipset: Support comments for ipset entries in the core Oliver
2013-09-02 20:08 ` [PATCH 0/6] Ipset comment extension - provide annotation of ipset entries Jozsef Kadlecsik
2013-09-02 21:05 ` Oliver
2013-09-03 8:43 ` Jozsef Kadlecsik
-- strict thread matches above, loose matches on Subject: below --
2013-09-17 13:13 [PATCH 0/6] Add new comments extension to ipset Oliver
2013-09-17 13:13 ` [PATCH 4/6] ipset: Rework the "fake" argument parsing for ipset restore Oliver
2013-09-18 18:22 ` Jozsef Kadlecsik
2013-09-19 14:56 ` Oliver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1378103757-14426-5-git-send-email-oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa \
--to=oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).