summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-05-06 00:23:13 +0200
committerFlorian Westphal <fw@strlen.de>2021-05-08 16:58:50 +0200
commitb2eb1c97507dde3b183012ea59a6533e0e0f4b8f (patch)
treee49e1e7192599143e5b10ca9a217faf8c20d04bb
parent38228087252c1d5da9dc88a09d3539e9882d808e (diff)
segtree: Fix range_mask_len() for subnet ranges exceeding unsigned int
As concatenated ranges are fetched from kernel sets and displayed to the user, range_mask_len() evaluates whether the range is suitable for display as netmask, and in that case it calculates the mask length by right-shifting the endpoints until no set bits are left, but in the existing version the temporary copies of the endpoints are derived by copying their unsigned int representation, which doesn't suffice for IPv6 netmask lengths, in general. PetrB reports that, after inserting a /56 subnet in a concatenated set element, it's listed as a /64 range. In fact, this happens for any IPv6 mask shorter than 64 bits. Fix this issue by simply sourcing the range endpoints provided by the caller and setting the temporary copies with mpz_init_set(), instead of fetching the unsigned int representation. The issue only affects displaying of the masks, setting elements already works as expected. Reported-by: PetrB <petr.boltik@gmail.com> Bugzilla: https://bugzilla.netfilter.org/show_bug.cgi?id=1520 Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r--src/segtree.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/segtree.c b/src/segtree.c
index ad199355..353a0053 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -838,8 +838,8 @@ static int range_mask_len(const mpz_t start, const mpz_t end, unsigned int len)
mpz_t tmp_start, tmp_end;
int ret;
- mpz_init_set_ui(tmp_start, mpz_get_ui(start));
- mpz_init_set_ui(tmp_end, mpz_get_ui(end));
+ mpz_init_set(tmp_start, start);
+ mpz_init_set(tmp_end, end);
while (mpz_cmp(tmp_start, tmp_end) <= 0 &&
!mpz_tstbit(tmp_start, 0) && mpz_tstbit(tmp_end, 0) &&