From 38763ab7cb701f7721b4b558952e85d09a935796 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 1 Dec 2014 10:29:32 +0100 Subject: [PATCH] fixed banning (hopefully) 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ban.c b/src/ban.c index 4ff47c8..c8b8688 100644 --- 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) -- 2.30.2