Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit c382ced

Browse files
author
mjseidel
committed
cluster: only assign debug port if in valid range.
See: #8159 Per above discussion, cluster.fork() currently sends --debug-port to forked processes regardless of whether debug is enabled, and more importantly, without any bounds checking. This will rather unexpectedly crash any Node process that forks enough times. This patch simply bounds checks --debug-port and doesn't set arg if out of bounds (V8 requires 1024 < debug-port < 65535). This will prevent surprises to callers of cluster.fork() while waiting for the debug part of node to be rewritten as mentioned in issue discussion above.
1 parent 4d9c81b commit c382ced

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/cluster.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,19 @@ function masterInit() {
307307
workerEnv = util._extend(workerEnv, env);
308308
workerEnv.NODE_UNIQUE_ID = '' + id;
309309

310-
for (var i = 0; i < execArgv.length; i++) {
311-
var match = execArgv[i].match(/^(--debug|--debug-brk)(=\d+)?$/);
310+
if (1024 < debugPort < 65535) {
311+
for (var i = 0; i < execArgv.length; i++) {
312+
var match = execArgv[i].match(/^(--debug|--debug-brk)(=\d+)?$/);
312313

313-
if (match) {
314-
execArgv[i] = match[1] + '=' + debugPort;
315-
hasDebugArg = true;
314+
if (match) {
315+
execArgv[i] = match[1] + '=' + debugPort;
316+
hasDebugArg = true;
317+
}
316318
}
317-
}
318319

319320
if (!hasDebugArg)
320321
execArgv = ['--debug-port=' + debugPort].concat(execArgv);
322+
}
321323

322324
return fork(cluster.settings.exec, cluster.settings.args, {
323325
env: workerEnv,

0 commit comments

Comments
 (0)