fixed banning (hopefully)
authorFelix Morgner <felix.morgner@gmail.com>
Mon, 1 Dec 2014 09:29:32 +0000 (10:29 +0100)
committerFelix Morgner <felix.morgner@gmail.com>
Mon, 1 Dec 2014 09:33:48 +0000 (10:33 +0100)
The original code used ^ which in C is the XOR operator. I believe the
author meant to raise 2 to the power of ban->mask, the new code should
calculate the mask correctly.

src/ban.c

index 4ff47c84232bc870b7d143f588c344d388ff1c95..c8b868809f0090a78465785ad6cdf2e097f523bc 100644 (file)
--- a/src/ban.c
+++ b/src/ban.c
@@ -144,7 +144,8 @@ bool_t Ban_isBannedAddr(struct sockaddr_storage *address)
                ban = list_get_entry(itr, ban_t, node);
                if (ban->address.ss_family == address->ss_family) {
                        if (address->ss_family == AF_INET) {
-                               uint32_t a1, a2, mask = 2 ^ ban->mask;
+                               uint32_t a1, a2, mask;
+                               mask = (ban->mask == 32) ? UINT32_MAX : (1u << ban->mask) - 1;
                                a1 = (uint32_t)((struct sockaddr_in *)&ban->address)->sin_addr.s_addr & mask;
                                a2 = (uint32_t)((struct sockaddr_in *)address)->sin_addr.s_addr & mask;
                                if (a1 == a2)