Skip to content

Commit

Permalink
cluster: only assign debug port if in valid range.
Browse files Browse the repository at this point in the history
See: nodejs#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 and 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.
  • Loading branch information
mjseidel committed Apr 13, 2015
1 parent 4d9c81b commit 167fbe4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,19 @@ function masterInit() {
workerEnv = util._extend(workerEnv, env);
workerEnv.NODE_UNIQUE_ID = '' + id;

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

if (match) {
execArgv[i] = match[1] + '=' + debugPort;
hasDebugArg = true;
if (match) {
execArgv[i] = match[1] + '=' + debugPort;
hasDebugArg = true;
}
}
}

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

return fork(cluster.settings.exec, cluster.settings.args, {
env: workerEnv,
Expand Down

0 comments on commit 167fbe4

Please sign in to comment.