Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/node_debug_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ int parse_and_validate_port(const std::string& port) {
char* endptr;
errno = 0;
const long result = strtol(port.c_str(), &endptr, 10); // NOLINT(runtime/int)
if (errno != 0 || *endptr != '\0'|| result < 1024 || result > 65535) {
if (errno != 0 || *endptr != '\0' ||
(result != 0 && (result < 1024 || result > 65535))) {
fprintf(stderr, "Debug port must be in range 1024 to 65535.\n");
exit(12);
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-inspector-ephemeral-port.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();

// Check that inspector can run on an ephemeral port.

const assert = require('assert');
const exec = require('child_process').exec;

const printA = require.resolve('../fixtures/printA.js');
const cmd = [
process.execPath,
'--inspect=0',
printA,
].join(' ');

exec(cmd, common.mustCall(function(err, _, stderr) {
assert.ifError(err);
const port1 = Number(stderr.match(/Debugger listening on port (\d+)/)[1]);
const port2 = Number(stderr.match(/chrome-devtools.*:(\d+)/)[1]);
assert.strictEqual(port1, port2);
assert(port1 > 0);
}));