File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ const {
2424 validateArray,
2525 validateInt32,
2626 validateOneOf,
27+ validatePort,
2728 validateString,
2829 validateUint32,
2930} = require ( 'internal/validators' ) ;
@@ -129,6 +130,7 @@ class ResolverBase {
129130 if ( ipVersion !== 0 ) {
130131 const port = NumberParseInt (
131132 RegExpPrototypeSymbolReplace ( addrSplitRE , serv , '$2' ) ) || IANA_DNS_PORT ;
133+ validatePort ( port ) ;
132134 return ArrayPrototypePush ( newSet , [ ipVersion , match [ 1 ] , port ] ) ;
133135 }
134136 }
@@ -138,13 +140,13 @@ class ResolverBase {
138140
139141 if ( addrSplitMatch ) {
140142 const hostIP = addrSplitMatch [ 1 ] ;
141- const port = addrSplitMatch [ 2 ] || IANA_DNS_PORT ;
143+ const port = NumberParseInt ( addrSplitMatch [ 2 ] ) || IANA_DNS_PORT ;
142144
143145 ipVersion = isIP ( hostIP ) ;
144146
145147 if ( ipVersion !== 0 ) {
146- return ArrayPrototypePush (
147- newSet , [ ipVersion , hostIP , NumberParseInt ( port ) ] ) ;
148+ validatePort ( port ) ;
149+ return ArrayPrototypePush ( newSet , [ ipVersion , hostIP , port ] ) ;
148150 }
149151 }
150152
Original file line number Diff line number Diff line change @@ -90,6 +90,22 @@ assert(existing.length > 0);
9090 } ) ;
9191}
9292
93+ {
94+ // Out-of-range ports, which should throw a clean error.
95+ const invalidPorts = [ 2 ** 16 , 2 ** 32 , 2 ** 64 ] ;
96+ invalidPorts . forEach ( ( port ) => {
97+ assert . throws (
98+ ( ) => {
99+ dns . setServers ( [ `1.2.3.4:${ port } ` ] ) ;
100+ } ,
101+ {
102+ name : 'RangeError' ,
103+ code : 'ERR_SOCKET_BAD_PORT'
104+ }
105+ ) ;
106+ } ) ;
107+ }
108+
93109const goog = [
94110 '8.8.8.8' ,
95111 '8.8.4.4' ,
You can’t perform that action at this time.
0 commit comments