| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 381e11e commit c736927
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,8 @@ const EventEmitter = require('events'); | |||
| 26 | 26 | const { queueMicrotask } = require('internal/process/task_queues'); | |
| 27 | 27 | const { | |
| 28 | 28 | validateCallback, | |
| 29 | + isUint32, | ||
| 30 | + validateInt32, | ||
| 29 | 31 | validateObject, | |
| 30 | 32 | validateString, | |
| 31 | 33 | } = require('internal/validators'); | |
@@ -167,6 +169,13 @@ function inspectorOpen(port, host, wait) { | |||
| 167 | 169 | if (isEnabled()) { | |
| 168 | 170 | throw new ERR_INSPECTOR_ALREADY_ACTIVATED(); | |
| 169 | 171 | } | |
| 172 | + // inspectorOpen() currently does not typecheck its arguments and adding | ||
| 173 | + // such checks would be a potentially breaking change. However, the native | ||
| 174 | + // open() function requires the port to fit into a 16-bit unsigned integer, | ||
| 175 | + // causing an integer overflow otherwise, so we at least need to prevent that. | ||
| 176 | + if (isUint32(port)) { | ||
| 177 | + validateInt32(port, 'port', 0, 65535); | ||
| 178 | + } | ||
| 170 | 179 | open(port, host); | |
| 171 | 180 | if (wait) | |
| 172 | 181 | waitForDebugger(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -281,6 +281,7 @@ void Open(const FunctionCallbackInfo<Value>& args) { | |||
| 281 | 281 | ||
| 282 | 282 | if (args.Length() > 0 && args[0]->IsUint32()) { | |
| 283 | 283 | uint32_t port = args[0].As<Uint32>()->Value(); | |
| 284 | + CHECK_LE(port, std::numeric_limits<uint16_t>::max()); | ||
| 284 | 285 | ExclusiveAccess<HostPort>::Scoped host_port(agent->host_port()); | |
| 285 | 286 | host_port->set_port(static_cast<int>(port)); | |
| 286 | 287 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Regression test for an integer overflow in inspector.open() when the port | ||
| 4 | + // exceeds the range of an unsigned 16-bit integer. | ||
| 5 | + | ||
| 6 | + const common = require('../common'); | ||
| 7 | + common.skipIfInspectorDisabled(); | ||
| 8 | + common.skipIfWorker(); | ||
| 9 | + | ||
| 10 | + const assert = require('assert'); | ||
| 11 | + const inspector = require('inspector'); | ||
| 12 | + | ||
| 13 | + assert.throws(() => inspector.open(99999), { | ||
| 14 | + name: 'RangeError', | ||
| 15 | + code: 'ERR_OUT_OF_RANGE', | ||
| 16 | + message: 'The value of "port" is out of range. It must be >= 0 && <= 65535. Received 99999' | ||
| 17 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments