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 --- extensions/libebt_ip.c | 3 ++- extensions/libebt_ip6.c | 2 +- extensions/libebt_stp.c | 3 ++- extensions/libip6t_DNAT.c | 4 +--- extensions/libip6t_SNAT.c | 4 +--- extensions/libip6t_dst.c | 8 +++----- extensions/libip6t_hbh.c | 7 +++---- extensions/libip6t_ipv6header.c | 2 +- extensions/libip6t_mh.c | 2 +- extensions/libip6t_rt.c | 7 +++---- extensions/libipt_DNAT.c | 8 ++------ extensions/libipt_SNAT.c | 4 +--- extensions/libxt_dccp.c | 2 +- extensions/libxt_hashlimit.c | 5 +---- extensions/libxt_iprange.c | 4 +--- extensions/libxt_multiport.c | 6 ++---- extensions/libxt_sctp.c | 4 ++-- extensions/libxt_set.h | 4 ++-- extensions/libxt_tcp.c | 4 ++-- 19 files changed, 32 insertions(+), 51 deletions(-) (limited to 'extensions') diff --git a/extensions/libebt_ip.c b/extensions/libebt_ip.c index acb9bfcd..51649ffb 100644 --- a/extensions/libebt_ip.c +++ b/extensions/libebt_ip.c @@ -175,7 +175,8 @@ parse_port_range(const char *protocol, const char *portstring, uint16_t *ports) char *buffer; char *cp; - buffer = strdup(portstring); + buffer = xtables_strdup(portstring); + if ((cp = strchr(buffer, ':')) == NULL) ports[0] = ports[1] = xtables_parse_port(buffer, NULL); else { diff --git a/extensions/libebt_ip6.c b/extensions/libebt_ip6.c index 3cc39271..a686a285 100644 --- a/extensions/libebt_ip6.c +++ b/extensions/libebt_ip6.c @@ -93,7 +93,7 @@ parse_port_range(const char *protocol, const char *portstring, uint16_t *ports) char *buffer; char *cp; - buffer = strdup(portstring); + buffer = xtables_strdup(portstring); if ((cp = strchr(buffer, ':')) == NULL) ports[0] = ports[1] = xtables_parse_port(buffer, NULL); else { diff --git a/extensions/libebt_stp.c b/extensions/libebt_stp.c index 81ba572c..3e9e2447 100644 --- a/extensions/libebt_stp.c +++ b/extensions/libebt_stp.c @@ -90,7 +90,8 @@ static int parse_range(const char *portstring, void *lower, void *upper, uint32_t low_nr, upp_nr; int ret = 0; - buffer = strdup(portstring); + buffer = xtables_strdup(portstring); + if ((cp = strchr(buffer, ':')) == NULL) { low_nr = strtoul(buffer, &end, 10); if (*end || low_nr < min || low_nr > max) { diff --git a/extensions/libip6t_DNAT.c b/extensions/libip6t_DNAT.c index 89c5ceb1..f1ad8143 100644 --- a/extensions/libip6t_DNAT.c +++ b/extensions/libip6t_DNAT.c @@ -58,9 +58,7 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range2 *range, int rev) char *arg, *start, *end = NULL, *colon = NULL, *dash, *error; const struct in6_addr *ip; - arg = strdup(orig_arg); - if (arg == NULL) - xtables_error(RESOURCE_PROBLEM, "strdup"); + arg = xtables_strdup(orig_arg); start = strchr(arg, '['); if (start == NULL) { diff --git a/extensions/libip6t_SNAT.c b/extensions/libip6t_SNAT.c index 7d74b3d7..6d19614c 100644 --- a/extensions/libip6t_SNAT.c +++ b/extensions/libip6t_SNAT.c @@ -52,9 +52,7 @@ parse_to(const char *orig_arg, int portok, struct nf_nat_range *range) char *arg, *start, *end = NULL, *colon = NULL, *dash, *error; const struct in6_addr *ip; - arg = strdup(orig_arg); - if (arg == NULL) - xtables_error(RESOURCE_PROBLEM, "strdup"); + arg = xtables_strdup(orig_arg); start = strchr(arg, '['); if (start == NULL) { diff --git a/extensions/libip6t_dst.c b/extensions/libip6t_dst.c index fe7e3403..bf0e3e43 100644 --- a/extensions/libip6t_dst.c +++ b/extensions/libip6t_dst.c @@ -57,11 +57,9 @@ parse_options(const char *optsstr, uint16_t *opts) { char *buffer, *cp, *next, *range; unsigned int i; - - buffer = strdup(optsstr); - if (!buffer) - xtables_error(OTHER_PROBLEM, "strdup failed"); - + + buffer = xtables_strdup(optsstr); + for (cp = buffer, i = 0; cp && i < IP6T_OPTS_OPTSNR; cp = next, i++) { next = strchr(cp, ','); diff --git a/extensions/libip6t_hbh.c b/extensions/libip6t_hbh.c index 4cebecfd..74e87cda 100644 --- a/extensions/libip6t_hbh.c +++ b/extensions/libip6t_hbh.c @@ -57,10 +57,9 @@ parse_options(const char *optsstr, uint16_t *opts) { char *buffer, *cp, *next, *range; unsigned int i; - - buffer = strdup(optsstr); - if (!buffer) xtables_error(OTHER_PROBLEM, "strdup failed"); - + + buffer = xtables_strdup(optsstr); + for (cp=buffer, i=0; cp && ipflags[i] = 0; diff --git a/extensions/libxt_sctp.c b/extensions/libxt_sctp.c index 5d8ab85c..a4c5415f 100644 --- a/extensions/libxt_sctp.c +++ b/extensions/libxt_sctp.c @@ -69,7 +69,7 @@ parse_sctp_ports(const char *portstring, char *buffer; char *cp; - buffer = strdup(portstring); + buffer = xtables_strdup(portstring); DEBUGP("%s\n", portstring); if ((cp = strchr(buffer, ':')) == NULL) { ports[0] = ports[1] = xtables_parse_port(buffer, "sctp"); @@ -164,7 +164,7 @@ parse_sctp_chunk(struct xt_sctp_info *einfo, int found = 0; char *chunk_flags; - buffer = strdup(chunks); + buffer = xtables_strdup(chunks); DEBUGP("Buffer: %s\n", buffer); SCTP_CHUNKMAP_RESET(einfo->chunkmap); diff --git a/extensions/libxt_set.h b/extensions/libxt_set.h index 41dfbd30..ad895a75 100644 --- a/extensions/libxt_set.h +++ b/extensions/libxt_set.h @@ -141,7 +141,7 @@ get_set_byname(const char *setname, struct xt_set_info *info) static void parse_dirs_v0(const char *opt_arg, struct xt_set_info_v0 *info) { - char *saved = strdup(opt_arg); + char *saved = xtables_strdup(opt_arg); char *ptr, *tmp = saved; int i = 0; @@ -167,7 +167,7 @@ parse_dirs_v0(const char *opt_arg, struct xt_set_info_v0 *info) static void parse_dirs(const char *opt_arg, struct xt_set_info *info) { - char *saved = strdup(opt_arg); + char *saved = xtables_strdup(opt_arg); char *ptr, *tmp = saved; while (info->dim < IPSET_DIM_MAX && tmp != NULL) { diff --git a/extensions/libxt_tcp.c b/extensions/libxt_tcp.c index 58f3c0a0..383e4db5 100644 --- a/extensions/libxt_tcp.c +++ b/extensions/libxt_tcp.c @@ -43,7 +43,7 @@ parse_tcp_ports(const char *portstring, uint16_t *ports) char *buffer; char *cp; - buffer = strdup(portstring); + buffer = xtables_strdup(portstring); if ((cp = strchr(buffer, ':')) == NULL) ports[0] = ports[1] = xtables_parse_port(buffer, "tcp"); else { @@ -83,7 +83,7 @@ parse_tcp_flag(const char *flags) char *ptr; char *buffer; - buffer = strdup(flags); + buffer = xtables_strdup(flags); for (ptr = strtok(buffer, ","); ptr; ptr = strtok(NULL, ",")) { unsigned int i; -- cgit v1.2.3