diff options
author | Florian Westphal <fw@strlen.de> | 2018-05-03 21:45:59 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2018-05-04 23:24:50 +0200 |
commit | 7af21782bb6fc3480909120c20a55164248a9608 (patch) | |
tree | 55d1f02d74df8f39125b449b3574c4745889ac65 /iptables/nft.c | |
parent | e9aeecf5956462f3a1b6cb21ea70280845948325 (diff) |
xtables-compat: fall back to comment match in case name is too long
... or when using multiple --comment lines.
This is more of a 'cosmetic' fix to handle the test suite case.
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'iptables/nft.c')
-rw-r--r-- | iptables/nft.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/iptables/nft.c b/iptables/nft.c index e7cb827b..76759251 100644 --- a/iptables/nft.c +++ b/iptables/nft.c @@ -1041,15 +1041,21 @@ enum udata_type { int add_comment(struct nftnl_rule *r, const char *comment) { struct nftnl_udata_buf *udata; - char comm[254]; + uint32_t len; + + if (nftnl_rule_get_data(r, NFTNL_RULE_USERDATA, &len)) + return -EALREADY; udata = nftnl_udata_buf_alloc(NFT_USERDATA_MAXLEN); if (!udata) return -ENOMEM; - snprintf(comm, sizeof(comm), "%s", comment); - if (!nftnl_udata_put_strz(udata, UDATA_TYPE_COMMENT, comm)) + if (strnlen(comment, 255) == 255) + return -ENOSPC; + + if (!nftnl_udata_put_strz(udata, UDATA_TYPE_COMMENT, comment)) return -ENOMEM; + nftnl_rule_set_data(r, NFTNL_RULE_USERDATA, nftnl_udata_buf_data(udata), nftnl_udata_buf_len(udata)); |