diff options
author | Andre Jodat-Danbrani <andre.jodat-danbrani@xe.com> | 2018-10-12 14:44:10 -0400 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-10-23 21:05:47 -0700 |
commit | cdba3c1de0de37576426421128982a4022480381 (patch) | |
tree | 9d6a4f455d6444fc8131a4cf1e31fcf506942754 /lib | |
parent | 51cd9719b5fde5da973dcdbb196402b49f885c63 (diff) | |
download | android-node-v8-cdba3c1de0de37576426421128982a4022480381.tar.gz android-node-v8-cdba3c1de0de37576426421128982a4022480381.tar.bz2 android-node-v8-cdba3c1de0de37576426421128982a4022480381.zip |
tls: throw if protocol too long
The convertProtocols() function now throws a range error when the byte
length of a protocol is too long to fit in a Buffer.
Also added a test case in test/parallel/test-tls-basic-validations.js
to cover this.
PR-URL: https://github.com/nodejs/node/pull/23606
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/errors.js | 7 | ||||
-rw-r--r-- | lib/tls.js | 9 |
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js index e8f1ed1a42..044303be5a 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -825,10 +825,11 @@ E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU', TypeError); E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported', Error); E('ERR_OUT_OF_RANGE', - (name, range, value) => { - let msg = `The value of "${name}" is out of range.`; + (str, range, input, replaceDefaultBoolean = false) => { + let msg = replaceDefaultBoolean ? str : + `The value of "${str}" is out of range.`; if (range !== undefined) msg += ` It must be ${range}.`; - msg += ` Received ${value}`; + msg += ` Received ${input}`; return msg; }, RangeError); E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s', Error); diff --git a/lib/tls.js b/lib/tls.js index 3335632c93..d6b86a4103 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -21,7 +21,10 @@ 'use strict'; -const { ERR_TLS_CERT_ALTNAME_INVALID } = require('internal/errors').codes; +const { + ERR_TLS_CERT_ALTNAME_INVALID, + ERR_OUT_OF_RANGE +} = require('internal/errors').codes; const internalUtil = require('internal/util'); const internalTLS = require('internal/tls'); internalUtil.assertCrypto(); @@ -60,6 +63,10 @@ function convertProtocols(protocols) { const lens = new Array(protocols.length); const buff = Buffer.allocUnsafe(protocols.reduce((p, c, i) => { var len = Buffer.byteLength(c); + if (len > 255) { + throw new ERR_OUT_OF_RANGE('The byte length of the protocol at index ' + + `${i} exceeds the maximum length.`, '<= 255', len, true); + } lens[i] = len; return p + 1 + len; }, 0)); |