From c8f6056f067a0bff2ac6c4cb2ea4eaeced122568 Mon Sep 17 00:00:00 2001 From: mjseidel Date: Mon, 13 Apr 2015 09:51:11 -0700 Subject: [PATCH 1/2] cluster: only assign debug port if in valid range. See: https://github.com/joyent/node/issues/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. --- lib/cluster.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/cluster.js b/lib/cluster.js index e05de4568bc..4e9e3e29d3e 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -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, From 3de2ae9f5832396b85b283381f30b7e480606141 Mon Sep 17 00:00:00 2001 From: mjseidel Date: Wed, 15 Apr 2015 13:23:35 -0700 Subject: [PATCH 2/2] Change conditional to match syntax in node.cc:2903 Additionally, fix previous commit's bug of disallowing 1024 and 65535, which are legal debug ports. --- lib/cluster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cluster.js b/lib/cluster.js index 4e9e3e29d3e..f8b35bed355 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -307,7 +307,7 @@ function masterInit() { workerEnv = util._extend(workerEnv, env); workerEnv.NODE_UNIQUE_ID = '' + id; - if (1024 < debugPort < 65535) { + if !(debug_port < 1024 || debug_port > 65535) { // If port in range according to node.cc:2903 for (var i = 0; i < execArgv.length; i++) { var match = execArgv[i].match(/^(--debug|--debug-brk)(=\d+)?$/);