Fix the thorrtler whitelist bitmask

Before we actually didn't check each bit of the bitmask. Now we do.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2019-02-11 23:22:20 +01:00
parent e3c787682d
commit f1ea56b502
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 33 additions and 2 deletions

View File

@ -177,8 +177,10 @@ class Throttler {
$part = ord($addr[(int)($i/8)]);
$orig = ord($ip[(int)($i/8)]);
$part = $part & (15 << (1 - ($i % 2)));
$orig = $orig & (15 << (1 - ($i % 2)));
$bitmask = 1 << (7 - ($i % 8));
$part = $part & $bitmask;
$orig = $orig & $bitmask;
if ($part !== $orig) {
$valid = false;

View File

@ -100,6 +100,27 @@ class ThrottlerTest extends TestCase {
],
true,
],
[
'10.10.10.10',
[
'whitelist_0' => '10.10.10.11/31',
],
true,
],
[
'10.10.10.10',
[
'whitelist_0' => '10.10.10.9/31',
],
false,
],
[
'10.10.10.10',
[
'whitelist_0' => '10.10.10.15/29',
],
true,
],
[
'dead:beef:cafe::1',
[
@ -127,6 +148,14 @@ class ThrottlerTest extends TestCase {
],
true,
],
[
'dead:beef:cafe::1111',
[
'whitelist_0' => 'dead:beef:cafe::1100/123',
],
true,
],
[
'invalid',
[],