From 0548e5d12ac32b6d58c8aac8bcf4dc8cff708b1f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 23 Jun 2016 22:10:49 -0700 Subject: [PATCH] child_process: add fork/execFile arg validation Validate fork/execFile arguments. Fixes: https://github.com/nodejs/node/issues/2681 Refs: https://github.com/nodejs/node/pull/4508 PR-URL: https://github.com/nodejs/node/pull/7399 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- lib/child_process.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 3736bc49ae61a5..d9be79925850b4 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -19,15 +19,20 @@ const ChildProcess = exports.ChildProcess = child_process.ChildProcess; exports.fork = function(modulePath /*, args, options*/) { // Get options and args arguments. - var options, args, execArgv; - if (Array.isArray(arguments[1])) { - args = arguments[1]; - options = util._extend({}, arguments[2]); - } else if (arguments[1] && typeof arguments[1] !== 'object') { - throw new TypeError('Incorrect value of args option'); - } else { - args = []; - options = util._extend({}, arguments[1]); + var execArgv; + var options = {}; + var args = []; + var pos = 1; + if (Array.isArray(arguments[pos])) { + args = arguments[pos++]; + } + + if (arguments[pos] != null) { + if (typeof arguments[pos] !== 'object') { + throw new TypeError('Incorrect value of args option'); + } else { + options = util._extend({}, arguments[pos++]); + } } // Prepare arguments for fork: @@ -132,7 +137,7 @@ exports.execFile = function(file /*, args, options, callback*/) { callback = arguments[pos++]; } - if (pos === 1 && arguments.length > 1) { + if (!callback && arguments[pos] != null) { throw new TypeError('Incorrect value of args option'); }