From a880cc28358a32f96467e248266973b6ab83f080 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 1 Feb 2019 19:17:50 +0100 Subject: xtables: Fix for crash when comparing rules with standard target When parsing an nftnl_rule with a standard verdict, nft_rule_to_iptables_command_state() initialized cs->target but didn't care about cs->target->t. When later comparing that rule to another, compare_targets() crashed due to unconditional access to t's fields. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- iptables/nft-shared.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'iptables/nft-shared.c') diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c index ca4e5936..2d4b8d55 100644 --- a/iptables/nft-shared.c +++ b/iptables/nft-shared.c @@ -660,19 +660,34 @@ void nft_rule_to_iptables_command_state(const struct nftnl_rule *r, match->m = m; } - if (cs->target != NULL) + if (cs->target != NULL) { cs->jumpto = cs->target->name; - else if (cs->jumpto != NULL) + } else if (cs->jumpto != NULL) { + struct xt_entry_target *t; + uint32_t size; + cs->target = xtables_find_target(cs->jumpto, XTF_TRY_LOAD); - else + if (!cs->target) + return; + + size = XT_ALIGN(sizeof(struct xt_entry_target)) + cs->target->size; + t = xtables_calloc(1, size); + t->u.target_size = size; + t->u.user.revision = cs->target->revision; + strcpy(t->u.user.name, cs->jumpto); + cs->target->t = t; + } else { cs->jumpto = ""; + } } void nft_clear_iptables_command_state(struct iptables_command_state *cs) { xtables_rule_matches_free(&cs->matches); - if (cs->target) + if (cs->target) { free(cs->target->t); + cs->target->t = NULL; + } } void print_header(unsigned int format, const char *chain, const char *pol, -- cgit v1.2.3