diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2020-12-31 12:49:44 +0100 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-01-11 12:44:41 +0100 |
commit | 307b79d2be12ad7fc16016a52469b76186a61e02 (patch) | |
tree | 24691f2d83d0b4ead5f71e3a9402b17559207e73 /lib/tls.js | |
parent | 6520a874eb94f5a5d653b6692ddfd444b469925e (diff) | |
download | node-new-307b79d2be12ad7fc16016a52469b76186a61e02.tar.gz |
tls: refactor to avoid unsafe array iteration
PR-URL: https://github.com/nodejs/node/pull/36772
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/tls.js')
-rw-r--r-- | lib/tls.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/tls.js b/lib/tls.js index 7ee9ae49f0..49c7d24517 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -24,6 +24,7 @@ const { Array, ArrayIsArray, + ArrayPrototypeForEach, ArrayPrototypeIncludes, ArrayPrototypeJoin, ArrayPrototypePush, @@ -31,6 +32,7 @@ const { ArrayPrototypeSome, ObjectDefineProperty, ObjectFreeze, + ReflectConstruct, RegExpPrototypeTest, StringFromCharCode, StringPrototypeCharCodeAt, @@ -214,7 +216,7 @@ function check(hostParts, pattern, wildcards) { if (patternParts.length <= 2) return false; - const [prefix, suffix] = patternSubdomainParts; + const { 0: prefix, 1: suffix } = patternSubdomainParts; if (prefix.length + suffix.length > hostSubdomain.length) return false; @@ -239,7 +241,8 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { hostname = '' + hostname; if (altNames) { - for (const name of StringPrototypeSplit(altNames, ', ')) { + const splitAltNames = StringPrototypeSplit(altNames, ', '); + ArrayPrototypeForEach(splitAltNames, (name) => { if (StringPrototypeStartsWith(name, 'DNS:')) { ArrayPrototypePush(dnsNames, StringPrototypeSlice(name, 4)); } else if (StringPrototypeStartsWith(name, 'URI:')) { @@ -264,7 +267,7 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { } else if (StringPrototypeStartsWith(name, 'IP Address:')) { ArrayPrototypePush(ips, canonicalizeIP(StringPrototypeSlice(name, 11))); } - } + }); } let valid = false; @@ -359,7 +362,7 @@ exports.connect = _tls_wrap.connect; exports.createSecurePair = internalUtil.deprecate( function createSecurePair(...args) { - return new SecurePair(...args); + return ReflectConstruct(SecurePair, args); }, 'tls.createSecurePair() is deprecated. Please use ' + 'tls.TLSSocket instead.', 'DEP0064'); |