summaryrefslogtreecommitdiffstats
path: root/iptables/nft-ipv4.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2018-04-13 19:19:57 +0200
committerFlorian Westphal <fw@strlen.de>2018-04-13 20:05:51 +0200
commit394a40030332568c8654d6960aa6f851bac9149d (patch)
tree396aa84d044767a7d9117af87bc9a7b23381777a /iptables/nft-ipv4.c
parent6a1dbdfb8c6aa5cfe24db2e5b2314c11c3d8e2df (diff)
nft: fix crash when getprotobynumber() returns 0
This needs to first check if pent is NULL. Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'iptables/nft-ipv4.c')
-rw-r--r--iptables/nft-ipv4.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/iptables/nft-ipv4.c b/iptables/nft-ipv4.c
index b779aef5..26d0d36c 100644
--- a/iptables/nft-ipv4.c
+++ b/iptables/nft-ipv4.c
@@ -460,15 +460,17 @@ static int nft_ipv4_xlate(const void *data, struct xt_xlate *xl)
const struct protoent *pent =
getprotobynumber(cs->fw.ip.proto);
char protonum[sizeof("65535")];
+ const char *name = protonum;
- if (!xlate_find_match(cs, pent->p_name)) {
- snprintf(protonum, sizeof(protonum), "%u",
- cs->fw.ip.proto);
- protonum[sizeof(protonum) - 1] = '\0';
+ snprintf(protonum, sizeof(protonum), "%u",
+ cs->fw.ip.proto);
+
+ if (!pent || !xlate_find_match(cs, pent->p_name)) {
+ if (pent)
+ name = pent->p_name;
xt_xlate_add(xl, "ip protocol %s%s ",
cs->fw.ip.invflags & IPT_INV_PROTO ?
- "!= " : "",
- pent ? pent->p_name : protonum);
+ "!= " : "", name);
}
}