| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c5588d7 commit 00c71fe
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ const { | |||
| 24 | 24 | validateArray, | |
| 25 | 25 | validateInt32, | |
| 26 | 26 | validateOneOf, | |
| 27 | + validatePort, | ||
| 27 | 28 | validateString, | |
| 28 | 29 | validateUint32, | |
| 29 | 30 | } = require('internal/validators'); | |
@@ -129,6 +130,7 @@ class ResolverBase { | |||
| 129 | 130 | if (ipVersion !== 0) { | |
| 130 | 131 | const port = NumberParseInt( | |
| 131 | 132 | RegExpPrototypeSymbolReplace(addrSplitRE, serv, '$2')) || IANA_DNS_PORT; | |
| 133 | + validatePort(port); | ||
| 132 | 134 | return ArrayPrototypePush(newSet, [ipVersion, match[1], port]); | |
| 133 | 135 | } | |
| 134 | 136 | } | |
@@ -138,13 +140,13 @@ class ResolverBase { | |||
| 138 | 140 | ||
| 139 | 141 | if (addrSplitMatch) { | |
| 140 | 142 | const hostIP = addrSplitMatch[1]; | |
| 141 | - const port = addrSplitMatch[2] || IANA_DNS_PORT; | ||
| 143 | + const port = NumberParseInt(addrSplitMatch[2]) || IANA_DNS_PORT; | ||
| 142 | 144 | ||
| 143 | 145 | ipVersion = isIP(hostIP); | |
| 144 | 146 | ||
| 145 | 147 | if (ipVersion !== 0) { | |
| 146 | - return ArrayPrototypePush( | ||
| 147 | - newSet, [ipVersion, hostIP, NumberParseInt(port)]); | ||
| 148 | + validatePort(port); | ||
| 149 | + return ArrayPrototypePush(newSet, [ipVersion, hostIP, port]); | ||
| 148 | 150 | } | |
| 149 | 151 | } | |
| 150 | 152 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,6 +90,22 @@ assert(existing.length > 0); | |||
| 90 | 90 | }); | |
| 91 | 91 | } | |
| 92 | 92 | ||
| 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 | + | ||
| 93 | 109 | const goog = [ | |
| 94 | 110 | '8.8.8.8', | |
| 95 | 111 | '8.8.4.4', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments