aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/addr.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-07 12:00:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-07 12:00:08 +0100
commitdabff7600bd0ae0cfb7d196eec83096bf0e38f25 (patch)
treeb59342a6a33d87f9616486f2842ebf34baeef701 /src/libutil/addr.c
parent1b5151533711e1c14f78c1e65c4902506b27ba1f (diff)
downloadrspamd-dabff7600bd0ae0cfb7d196eec83096bf0e38f25.tar.gz
rspamd-dabff7600bd0ae0cfb7d196eec83096bf0e38f25.zip
[CritFix] Fix application of IPv6 mask
MFH: true
Diffstat (limited to 'src/libutil/addr.c')
-rw-r--r--src/libutil/addr.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index a6aa8a878..0bc7aa85a 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -1321,12 +1321,21 @@ rspamd_inet_address_apply_mask (rspamd_inet_addr_t *addr, guint mask)
}
else if (addr->af == AF_INET6 && mask <= 128) {
p = (uint32_t *)&addr->u.in.addr.s6.sin6_addr;
+ mask = 128 - mask;
p += 3;
- while (mask > 0) {
- umsk = htonl (G_MAXUINT32 << (32 - (mask > 32 ? 32 : mask)));
- *p &= umsk;
+
+ for (;;) {
+ if (mask > 32) {
+ mask -= 32;
+ *p = 0;
+ }
+ else {
+ umsk = htonl (G_MAXUINT32 << mask);
+ *p &= umsk;
+ break;
+ }
+
p --;
- mask -= 32;
}
}
}