mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
net: prevent /32 ipv4 mask from matching all ips
Fixes: https://github.com/nodejs/node/issues/43360 PR-URL: https://github.com/nodejs/node/pull/43381 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
@@ -215,7 +215,7 @@ bool in_network_ipv4(
|
||||
const SocketAddress& ip,
|
||||
const SocketAddress& net,
|
||||
int prefix) {
|
||||
uint32_t mask = ((1 << prefix) - 1) << (32 - prefix);
|
||||
uint32_t mask = ((1ull << prefix) - 1) << (32 - prefix);
|
||||
|
||||
const sockaddr_in* ip_in =
|
||||
reinterpret_cast<const sockaddr_in*>(ip.data());
|
||||
@@ -293,7 +293,7 @@ bool in_network_ipv6_ipv4(
|
||||
if (prefix == 32)
|
||||
return compare_ipv4_ipv6(net, ip) == SocketAddress::CompareResult::SAME;
|
||||
|
||||
uint32_t m = ((1 << prefix) - 1) << (32 - prefix);
|
||||
uint32_t m = ((1ull << prefix) - 1) << (32 - prefix);
|
||||
|
||||
const sockaddr_in6* ip_in =
|
||||
reinterpret_cast<const sockaddr_in6*>(ip.data());
|
||||
|
||||
@@ -272,3 +272,13 @@ const util = require('util');
|
||||
const ret = util.inspect(blockList, { depth: null });
|
||||
assert(ret.includes('rules: []'));
|
||||
}
|
||||
|
||||
{
|
||||
// Test for https://github.com/nodejs/node/issues/43360
|
||||
const blocklist = new BlockList();
|
||||
blocklist.addSubnet('1.1.1.1', 32, 'ipv4');
|
||||
|
||||
assert(blocklist.check('1.1.1.1'));
|
||||
assert(!blocklist.check('1.1.1.2'));
|
||||
assert(!blocklist.check('2.3.4.5'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user