File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -159,10 +159,12 @@ SocketAddress::CompareResult compare_ipv4(
159
159
reinterpret_cast <const sockaddr_in*>(one.data ());
160
160
const sockaddr_in* two_in =
161
161
reinterpret_cast <const sockaddr_in*>(two.data ());
162
+ const uint32_t s_addr_one = ntohl (one_in->sin_addr .s_addr );
163
+ const uint32_t s_addr_two = ntohl (two_in->sin_addr .s_addr );
162
164
163
- if (one_in-> sin_addr . s_addr < two_in-> sin_addr . s_addr )
165
+ if (s_addr_one < s_addr_two )
164
166
return SocketAddress::CompareResult::LESS_THAN;
165
- else if (one_in-> sin_addr . s_addr == two_in-> sin_addr . s_addr )
167
+ else if (s_addr_one == s_addr_two )
166
168
return SocketAddress::CompareResult::SAME;
167
169
else
168
170
return SocketAddress::CompareResult::GREATER_THAN;
Original file line number Diff line number Diff line change @@ -209,6 +209,27 @@ const util = require('util');
209
209
assert ( ! blockList . check ( '8592:757c:efaf:2fff:ffff:ffff:ffff:ffff' , 'ipv6' ) ) ;
210
210
}
211
211
212
+ {
213
+ // Regression test for https://github.com/nodejs/node/issues/39074
214
+ const blockList = new BlockList ( ) ;
215
+
216
+ blockList . addRange ( '10.0.0.2' , '10.0.0.10' ) ;
217
+
218
+ // IPv4 checks against IPv4 range.
219
+ assert ( blockList . check ( '10.0.0.2' ) ) ;
220
+ assert ( blockList . check ( '10.0.0.10' ) ) ;
221
+ assert ( ! blockList . check ( '192.168.0.3' ) ) ;
222
+ assert ( ! blockList . check ( '2.2.2.2' ) ) ;
223
+ assert ( ! blockList . check ( '255.255.255.255' ) ) ;
224
+
225
+ // IPv6 checks against IPv4 range.
226
+ assert ( blockList . check ( '::ffff:0a00:0002' , 'ipv6' ) ) ;
227
+ assert ( blockList . check ( '::ffff:0a00:000a' , 'ipv6' ) ) ;
228
+ assert ( ! blockList . check ( '::ffff:c0a8:0003' , 'ipv6' ) ) ;
229
+ assert ( ! blockList . check ( '::ffff:0202:0202' , 'ipv6' ) ) ;
230
+ assert ( ! blockList . check ( '::ffff:ffff:ffff' , 'ipv6' ) ) ;
231
+ }
232
+
212
233
{
213
234
const blockList = new BlockList ( ) ;
214
235
assert . throws ( ( ) => blockList . addRange ( '1.1.1.2' , '1.1.1.1' ) , / E R R _ I N V A L I D _ A R G _ V A L U E / ) ;
You can’t perform that action at this time.
0 commit comments