summaryrefslogtreecommitdiffstats
path: root/iptables/xtables-restore.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2019-10-17 23:36:47 +0200
committerPhil Sutter <phil@nwl.cc>2019-10-24 16:22:52 +0200
commit9376c42a59929031610ea70d2fc6347fbfa46e67 (patch)
tree026389796b060b491903131ee8102d035c98dbfd /iptables/xtables-restore.c
parentf8ec1b7a296e6f461278937213a1477e4d29b1f3 (diff)
xshared: Introduce struct argv_store
The use of global variables in code around add_argv() is error-prone and hard to follow. Replace them by a struct which functions will modify instead of causing side-effects. Given the lack of static variables, this effectively makes argv construction code reentrant. Signed-off-by: Phil Sutter <phil@nwl.cc> Acked-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'iptables/xtables-restore.c')
-rw-r--r--iptables/xtables-restore.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
index 1c7d5da5..8d6cb7a9 100644
--- a/iptables/xtables-restore.c
+++ b/iptables/xtables-restore.c
@@ -73,6 +73,7 @@ void xtables_restore_parse(struct nft_handle *h,
const struct nft_xt_restore_cb *cb)
{
const struct builtin_table *curtable = NULL;
+ struct argv_store av_store = {};
char buffer[10240];
int in_table = 0;
@@ -209,35 +210,29 @@ void xtables_restore_parse(struct nft_handle *h,
}
ret = 1;
} else if (in_table) {
- int a;
char *pcnt = NULL;
char *bcnt = NULL;
char *parsestart = buffer;
- /* reset the newargv */
- newargc = 0;
-
- add_argv(xt_params->program_name, 0);
- add_argv("-t", 0);
- add_argv(curtable->name, 0);
+ add_argv(&av_store, xt_params->program_name, 0);
+ add_argv(&av_store, "-t", 0);
+ add_argv(&av_store, curtable->name, 0);
tokenize_rule_counters(&parsestart, &pcnt, &bcnt, line);
if (counters && pcnt && bcnt) {
- add_argv("--set-counters", 0);
- add_argv(pcnt, 0);
- add_argv(bcnt, 0);
+ add_argv(&av_store, "--set-counters", 0);
+ add_argv(&av_store, pcnt, 0);
+ add_argv(&av_store, bcnt, 0);
}
- add_param_to_argv(parsestart, line);
+ add_param_to_argv(&av_store, parsestart, line);
DEBUGP("calling do_command4(%u, argv, &%s, handle):\n",
- newargc, curtable->name);
-
- for (a = 0; a < newargc; a++)
- DEBUGP("argv[%u]: %s\n", a, newargv[a]);
+ av_store.argc, curtable->name);
+ debug_print_argv(&av_store);
- ret = cb->do_command(h, newargc, newargv,
- &newargv[2], true);
+ ret = cb->do_command(h, av_store.argc, av_store.argv,
+ &av_store.argv[2], true);
if (ret < 0) {
if (cb->abort)
ret = cb->abort(h);
@@ -251,7 +246,7 @@ void xtables_restore_parse(struct nft_handle *h,
exit(1);
}
- free_argv();
+ free_argv(&av_store);
fflush(stdout);
}
if (p->tablename && curtable &&