From 167fbe4081e22c1be7b7ee5076c83b9e38151167 Mon Sep 17 00:00:00 2001 From: mjseidel Date: Mon, 13 Apr 2015 12:14:10 -0700 Subject: [PATCH] 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 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. --- 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,