From: Xiao Liang <shaw.leon@gmail.com>
To: netfilter-devel <netfilter-devel@vger.kernel.org>
Cc: Xiao Liang <shaw.leon@gmail.com>
Subject: [PATCH nft] src: Check range bounds before converting to prefix
Date: Mon, 6 Sep 2021 11:06:41 +0800 [thread overview]
Message-ID: <20210906030641.10958-1-shaw.leon@gmail.com> (raw)
The lower bound must be the first value of the prefix to be coverted.
For example, range "10.0.0.15-10.0.0.240" can not be converted to
"10.0.0.15/24". Validate it by checking if the lower bound value has
enough trailing zeros.
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
src/netlink.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/netlink.c b/src/netlink.c
index cbf9d436..0fd0b664 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -1079,12 +1079,15 @@ struct expr *range_expr_to_prefix(struct expr *range)
if (mpz_bitmask_is_prefix(bitmask, len)) {
prefix_len = mpz_bitmask_to_prefix(bitmask, len);
- prefix = prefix_expr_alloc(&range->location, expr_get(left),
- prefix_len);
- mpz_clear(bitmask);
- expr_free(range);
-
- return prefix;
+ if (mpz_scan1(left->value, 0) >= len - prefix_len) {
+ prefix = prefix_expr_alloc(&range->location,
+ expr_get(left),
+ prefix_len);
+ mpz_clear(bitmask);
+ expr_free(range);
+
+ return prefix;
+ }
}
mpz_clear(bitmask);
--
2.33.0
next reply other threads:[~2021-09-06 3:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-06 3:06 Xiao Liang [this message]
2021-09-06 9:13 ` [PATCH nft] src: Check range bounds before converting to prefix Pablo Neira Ayuso
2021-09-06 12:57 ` Xiao Liang
2021-09-06 20:04 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210906030641.10958-1-shaw.leon@gmail.com \
--to=shaw.leon@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.