From e07872e5f404aee90d06081d10cd1eea89647b4d Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 29 Sep 2014 11:26:43 -0700 Subject: [PATCH] child_process: check fork args is an array Optional fork args should be type-checked with same behaviour as the equivalent argument to spawn. --- lib/child_process.js | 2 ++ test/simple/test-child-process-spawn-typeerror.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/child_process.js b/lib/child_process.js index 2596547f7a7d..7bc1dafe891a 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -525,6 +525,8 @@ exports.fork = function(modulePath /*, args, options*/) { 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]); diff --git a/test/simple/test-child-process-spawn-typeerror.js b/test/simple/test-child-process-spawn-typeerror.js index b5d1249e5883..e28bd2a519a4 100644 --- a/test/simple/test-child-process-spawn-typeerror.js +++ b/test/simple/test-child-process-spawn-typeerror.js @@ -22,8 +22,10 @@ var assert = require('assert'); var child_process = require('child_process'); var spawn = child_process.spawn; +var fork = child_process.fork; var execFile = child_process.execFile; var cmd = (process.platform === 'win32') ? 'dir' : 'ls'; +var empty = require('../common').fixturesDir + '/empty.js'; // verify that args argument must be an array @@ -45,3 +47,12 @@ assert.throws(function() { assert.doesNotThrow(function() { execFile(cmd, {}); }); + +// verify that fork has same argument parsing behaviour as spawn +assert.throws(function() { + fork(empty, 'this is not an array'); +}, TypeError); + +assert.doesNotThrow(function() { + execFile(empty, {}); +});