File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 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(
159159 reinterpret_cast <const sockaddr_in*>(one.data ());
160160 const sockaddr_in* two_in =
161161 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 );
162164
163- if (one_in-> sin_addr . s_addr < two_in-> sin_addr . s_addr )
165+ if (s_addr_one < s_addr_two )
164166 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 )
166168 return SocketAddress::CompareResult::SAME;
167169 else
168170 return SocketAddress::CompareResult::GREATER_THAN;
Original file line number Diff line number Diff line change @@ -209,6 +209,27 @@ const util = require('util');
209209 assert ( ! blockList . check ( '8592:757c:efaf:2fff:ffff:ffff:ffff:ffff' , 'ipv6' ) ) ;
210210}
211211
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+
212233{
213234 const blockList = new BlockList ( ) ;
214235 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