From 9b85e1ab3dbf0d9344562c5c76114496e3ebaa3a Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 2 Jun 2021 12:56:06 +0200 Subject: libxtables: Introduce xtables_strdup() and use it everywhere This wraps strdup(), checking for errors. Signed-off-by: Phil Sutter --- iptables/iptables-xml.c | 4 ++-- iptables/nft-cache.c | 4 ++-- iptables/nft-cmd.c | 13 +++++++------ iptables/xshared.c | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) (limited to 'iptables') diff --git a/iptables/iptables-xml.c b/iptables/iptables-xml.c index 98d03dda..6cf059fb 100644 --- a/iptables/iptables-xml.c +++ b/iptables/iptables-xml.c @@ -213,8 +213,8 @@ saveChain(char *chain, char *policy, struct xt_counters *ctr) "%s: line %u chain name invalid\n", prog_name, line); - chains[nextChain].chain = strdup(chain); - chains[nextChain].policy = strdup(policy); + chains[nextChain].chain = xtables_strdup(chain); + chains[nextChain].policy = xtables_strdup(policy); chains[nextChain].count = *ctr; chains[nextChain].created = 0; nextChain++; diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c index 8fbf9727..2c88301c 100644 --- a/iptables/nft-cache.c +++ b/iptables/nft-cache.c @@ -40,7 +40,7 @@ static void cache_chain_list_insert(struct list_head *list, const char *name) } new = xtables_malloc(sizeof(*new)); - new->name = strdup(name); + new->name = xtables_strdup(name); list_add_tail(&new->head, pos ? &pos->head : list); } @@ -56,7 +56,7 @@ void nft_cache_level_set(struct nft_handle *h, int level, return; if (!req->table) - req->table = strdup(cmd->table); + req->table = xtables_strdup(cmd->table); else assert(!strcmp(req->table, cmd->table)); diff --git a/iptables/nft-cmd.c b/iptables/nft-cmd.c index c3f6c14e..a0c76a79 100644 --- a/iptables/nft-cmd.c +++ b/iptables/nft-cmd.c @@ -11,6 +11,7 @@ #include #include +#include #include "nft.h" #include "nft-cmd.h" @@ -27,9 +28,9 @@ struct nft_cmd *nft_cmd_new(struct nft_handle *h, int command, return NULL; cmd->command = command; - cmd->table = strdup(table); + cmd->table = xtables_strdup(table); if (chain) - cmd->chain = strdup(chain); + cmd->chain = xtables_strdup(chain); cmd->rulenum = rulenum; cmd->verbose = verbose; @@ -43,7 +44,7 @@ struct nft_cmd *nft_cmd_new(struct nft_handle *h, int command, cmd->obj.rule = rule; if (!state->target && strlen(state->jumpto) > 0) - cmd->jumpto = strdup(state->jumpto); + cmd->jumpto = xtables_strdup(state->jumpto); } list_add_tail(&cmd->head, &h->cmd_list); @@ -238,7 +239,7 @@ int nft_cmd_chain_user_rename(struct nft_handle *h,const char *chain, if (!cmd) return 0; - cmd->rename = strdup(newname); + cmd->rename = xtables_strdup(newname); nft_cache_level_set(h, NFT_CL_CHAINS, cmd); @@ -304,7 +305,7 @@ int nft_cmd_chain_set(struct nft_handle *h, const char *table, if (!cmd) return 0; - cmd->policy = strdup(policy); + cmd->policy = xtables_strdup(policy); if (counters) cmd->counters = *counters; @@ -389,7 +390,7 @@ int ebt_cmd_user_chain_policy(struct nft_handle *h, const char *table, if (!cmd) return 0; - cmd->policy = strdup(policy); + cmd->policy = xtables_strdup(policy); nft_cache_level_set(h, NFT_CL_RULES, cmd); diff --git a/iptables/xshared.c b/iptables/xshared.c index 49a88de5..ed3e9c5a 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -435,7 +435,7 @@ void add_argv(struct argv_store *store, const char *what, int quoted) xtables_error(PARAMETER_PROBLEM, "Trying to store NULL argument\n"); - store->argv[store->argc] = strdup(what); + store->argv[store->argc] = xtables_strdup(what); store->argvattr[store->argc] = quoted; store->argv[++store->argc] = NULL; } -- cgit v1.2.3