|
|
8cce6c |
From da5f63cd381cb109b73d2d31f5da35242bf5ae99 Mon Sep 17 00:00:00 2001
|
|
|
8cce6c |
From: Phil Sutter <phil@nwl.cc>
|
|
|
8cce6c |
Date: Thu, 7 Feb 2019 22:08:53 +0100
|
|
|
8cce6c |
Subject: [PATCH] nft: Don't assume NFTNL_RULE_USERDATA holds a comment
|
|
|
8cce6c |
|
|
|
8cce6c |
If this rule attribute is present but does not contain a comment,
|
|
|
8cce6c |
get_comment() returns NULL which is then fed into strncpy() causing a
|
|
|
8cce6c |
crash.
|
|
|
8cce6c |
|
|
|
8cce6c |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
8cce6c |
Signed-off-by: Florian Westphal <fw@strlen.de>
|
|
|
8cce6c |
(cherry picked from commit d1df0a36b0486c780211cfa574301132bf55f194)
|
|
|
8cce6c |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
8cce6c |
---
|
|
|
8cce6c |
iptables/nft-shared.c | 39 ++++++++++++++++++++++-----------------
|
|
|
8cce6c |
1 file changed, 22 insertions(+), 17 deletions(-)
|
|
|
8cce6c |
|
|
|
8cce6c |
diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c
|
|
|
8cce6c |
index ce40787f92f7d..fc484b49e2318 100644
|
|
|
8cce6c |
--- a/iptables/nft-shared.c
|
|
|
8cce6c |
+++ b/iptables/nft-shared.c
|
|
|
8cce6c |
@@ -639,25 +639,30 @@ void nft_rule_to_iptables_command_state(const struct nftnl_rule *r,
|
|
|
8cce6c |
if (nftnl_rule_is_set(r, NFTNL_RULE_USERDATA)) {
|
|
|
8cce6c |
const void *data;
|
|
|
8cce6c |
uint32_t len, size;
|
|
|
8cce6c |
- struct xtables_match *match;
|
|
|
8cce6c |
- struct xt_entry_match *m;
|
|
|
8cce6c |
+ const char *comment;
|
|
|
8cce6c |
|
|
|
8cce6c |
data = nftnl_rule_get_data(r, NFTNL_RULE_USERDATA, &len;;
|
|
|
8cce6c |
- match = xtables_find_match("comment", XTF_TRY_LOAD,
|
|
|
8cce6c |
- &cs->matches);
|
|
|
8cce6c |
- if (match == NULL)
|
|
|
8cce6c |
- return;
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- size = XT_ALIGN(sizeof(struct xt_entry_match)) + match->size;
|
|
|
8cce6c |
- m = xtables_calloc(1, size);
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- strncpy((char *)m->data, get_comment(data, len),
|
|
|
8cce6c |
- match->size - 1);
|
|
|
8cce6c |
- m->u.match_size = size;
|
|
|
8cce6c |
- m->u.user.revision = 0;
|
|
|
8cce6c |
- strcpy(m->u.user.name, match->name);
|
|
|
8cce6c |
-
|
|
|
8cce6c |
- match->m = m;
|
|
|
8cce6c |
+ comment = get_comment(data, len);
|
|
|
8cce6c |
+ if (comment) {
|
|
|
8cce6c |
+ struct xtables_match *match;
|
|
|
8cce6c |
+ struct xt_entry_match *m;
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ match = xtables_find_match("comment", XTF_TRY_LOAD,
|
|
|
8cce6c |
+ &cs->matches);
|
|
|
8cce6c |
+ if (match == NULL)
|
|
|
8cce6c |
+ return;
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ size = XT_ALIGN(sizeof(struct xt_entry_match))
|
|
|
8cce6c |
+ + match->size;
|
|
|
8cce6c |
+ m = xtables_calloc(1, size);
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ strncpy((char *)m->data, comment, match->size - 1);
|
|
|
8cce6c |
+ m->u.match_size = size;
|
|
|
8cce6c |
+ m->u.user.revision = 0;
|
|
|
8cce6c |
+ strcpy(m->u.user.name, match->name);
|
|
|
8cce6c |
+
|
|
|
8cce6c |
+ match->m = m;
|
|
|
8cce6c |
+ }
|
|
|
8cce6c |
}
|
|
|
8cce6c |
|
|
|
8cce6c |
if (cs->target != NULL) {
|
|
|
8cce6c |
--
|
|
|
8cce6c |
2.20.1
|
|
|
8cce6c |
|