From 9376c42a59929031610ea70d2fc6347fbfa46e67 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 17 Oct 2019 23:36:47 +0200 Subject: 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 Acked-by: Florian Westphal --- iptables/xshared.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'iptables/xshared.h') diff --git a/iptables/xshared.h b/iptables/xshared.h index 21f4e8fd..64b7e8fc 100644 --- a/iptables/xshared.h +++ b/iptables/xshared.h @@ -156,18 +156,22 @@ bool xs_has_arg(int argc, char *argv[]); extern const struct xtables_afinfo *afinfo; -extern char *newargv[]; -extern int newargc; - -extern char *oldargv[]; -extern int oldargc; - -extern int newargvattr[]; +#define MAX_ARGC 255 +struct argv_store { + int argc; + char *argv[MAX_ARGC]; + int argvattr[MAX_ARGC]; +}; -int add_argv(const char *what, int quoted); -void free_argv(void); -void save_argv(void); -void add_param_to_argv(char *parsestart, int line); +void add_argv(struct argv_store *store, const char *what, int quoted); +void free_argv(struct argv_store *store); +void save_argv(struct argv_store *dst, struct argv_store *src); +void add_param_to_argv(struct argv_store *store, char *parsestart, int line); +#ifdef DEBUG +void debug_print_argv(struct argv_store *store); +#else +# define debug_print_argv(...) /* nothing */ +#endif void print_ipv4_addresses(const struct ipt_entry *fw, unsigned int format); void print_ipv6_addresses(const struct ip6t_entry *fw6, unsigned int format); -- cgit v1.2.3