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 @@ -158,10 +158,12 @@ SocketAddress::CompareResult compare_ipv4(
158158 reinterpret_cast <const sockaddr_in*>(one.data ());
159159 const sockaddr_in* two_in =
160160 reinterpret_cast <const sockaddr_in*>(two.data ());
161+ const uint32_t s_addr_one = ntohl (one_in->sin_addr .s_addr );
162+ const uint32_t s_addr_two = ntohl (two_in->sin_addr .s_addr );
161163
162- if (one_in-> sin_addr . s_addr < two_in-> sin_addr . s_addr )
164+ if (s_addr_one < s_addr_two )
163165 return SocketAddress::CompareResult::LESS_THAN;
164- else if (one_in-> sin_addr . s_addr == two_in-> sin_addr . s_addr )
166+ else if (s_addr_one == s_addr_two )
165167 return SocketAddress::CompareResult::SAME;
166168 else
167169 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