From 394a40030332568c8654d6960aa6f851bac9149d Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Fri, 13 Apr 2018 19:19:57 +0200 Subject: nft: fix crash when getprotobynumber() returns 0 This needs to first check if pent is NULL. Signed-off-by: Florian Westphal --- iptables/nft-ipv6.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'iptables/nft-ipv6.c') diff --git a/iptables/nft-ipv6.c b/iptables/nft-ipv6.c index 1be49dd3..af525422 100644 --- a/iptables/nft-ipv6.c +++ b/iptables/nft-ipv6.c @@ -417,16 +417,19 @@ static int nft_ipv6_xlate(const void *data, struct xt_xlate *xl) const struct protoent *pent = getprotobynumber(cs->fw6.ipv6.proto); char protonum[sizeof("65535")]; + const char *name = protonum; - if (!xlate_find_match(cs, pent->p_name)) { - snprintf(protonum, sizeof(protonum), "%u", - cs->fw6.ipv6.proto); - protonum[sizeof(protonum) - 1] = '\0'; + snprintf(protonum, sizeof(protonum), "%u", + cs->fw6.ipv6.proto); + + if (!pent || !xlate_find_match(cs, pent->p_name)) { + if (pent) + name = pent->p_name; xt_xlate_add(xl, "meta l4proto %s%s ", cs->fw6.ipv6.invflags & IP6T_INV_PROTO ? - "!= " : "", - pent ? pent->p_name : protonum); + "!= " : "", name); } + } xlate_ipv6_addr("ip6 saddr", &cs->fw6.ipv6.src, &cs->fw6.ipv6.smsk, -- cgit v1.2.3