| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 756d2e4 commit 13c931a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | #include "env-inl.h" | |
| 2 | + #include "node_errors.h" | ||
| 2 | 3 | #include "node_external_reference.h" | |
| 3 | 4 | #include "node_internals.h" | |
| 4 | 5 | #include "node_metadata.h" | |
@@ -60,6 +61,13 @@ static void DebugPortSetter(Local<Name> property, | |||
| 60 | 61 | const PropertyCallbackInfo<void>& info) { | |
| 61 | 62 | Environment* env = Environment::GetCurrent(info); | |
| 62 | 63 | int32_t port = value->Int32Value(env->context()).FromMaybe(0); | |
| 64 | + | ||
| 65 | + if ((port != 0 && port < 1024) || port > 65535) { | ||
| 66 | + return THROW_ERR_OUT_OF_RANGE( | ||
| 67 | + env, | ||
| 68 | + "process.debugPort must be 0 or in range 1024 to 65535"); | ||
| 69 | + } | ||
| 70 | + | ||
| 63 | 71 | ExclusiveAccess<HostPort>::Scoped host_port(env->inspector_host_port()); | |
| 64 | 72 | host_port->set_port(static_cast<int>(port)); | |
| 65 | 73 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,60 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + common.skipIfInspectorDisabled(); | ||
| 5 | + common.skipIfWorker(); | ||
| 6 | + | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const kMinPort = 1024; | ||
| 9 | + const kMaxPort = 65535; | ||
| 10 | + | ||
| 11 | + function check(value, expected) { | ||
| 12 | + process.debugPort = value; | ||
| 13 | + assert.strictEqual(process.debugPort, expected); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + // Expected usage with numbers. | ||
| 17 | + check(0, 0); | ||
| 18 | + check(kMinPort, kMinPort); | ||
| 19 | + check(kMinPort + 1, kMinPort + 1); | ||
| 20 | + check(kMaxPort - 1, kMaxPort - 1); | ||
| 21 | + check(kMaxPort, kMaxPort); | ||
| 22 | + | ||
| 23 | + // Numeric strings coerce. | ||
| 24 | + check('0', 0); | ||
| 25 | + check(`${kMinPort}`, kMinPort); | ||
| 26 | + check(`${kMinPort + 1}`, kMinPort + 1); | ||
| 27 | + check(`${kMaxPort - 1}`, kMaxPort - 1); | ||
| 28 | + check(`${kMaxPort}`, kMaxPort); | ||
| 29 | + | ||
| 30 | + // Most other values are coerced to 0. | ||
| 31 | + check('', 0); | ||
| 32 | + check(false, 0); | ||
| 33 | + check(NaN, 0); | ||
| 34 | + check(Infinity, 0); | ||
| 35 | + check(-Infinity, 0); | ||
| 36 | + check(function() {}, 0); | ||
| 37 | + check({}, 0); | ||
| 38 | + check([], 0); | ||
| 39 | + | ||
| 40 | + // Symbols do not coerce. | ||
| 41 | + assert.throws(() => { | ||
| 42 | + process.debugPort = Symbol(); | ||
| 43 | + }, /^TypeError: Cannot convert a Symbol value to a number$/); | ||
| 44 | + | ||
| 45 | + // Verify port bounds checking. | ||
| 46 | + [ | ||
| 47 | + true, | ||
| 48 | + -1, | ||
| 49 | + 1, | ||
| 50 | + kMinPort - 1, | ||
| 51 | + kMaxPort + 1, | ||
| 52 | + '-1', | ||
| 53 | + '1', | ||
| 54 | + `${kMinPort - 1}`, | ||
| 55 | + `${kMaxPort + 1}`, | ||
| 56 | + ].forEach((value) => { | ||
| 57 | + assert.throws(() => { | ||
| 58 | + process.debugPort = value; | ||
| 59 | + }, /^RangeError: process\.debugPort must be 0 or in range 1024 to 65535$/); | ||
| 60 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments