Skip to content

Commit

Permalink
child_process: add fork/execFile arg validation
Browse files Browse the repository at this point in the history
Validate fork/execFile arguments.

Fixes: #2681
Refs: #4508
PR-URL: #7399
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott committed Jun 30, 2016
1 parent 0268fd0 commit 0548e5d
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/child_process.js
Expand Up @@ -19,15 +19,20 @@ const ChildProcess = exports.ChildProcess = child_process.ChildProcess;
exports.fork = function(modulePath /*, args, options*/) { exports.fork = function(modulePath /*, args, options*/) {


// Get options and args arguments. // Get options and args arguments.
var options, args, execArgv; var execArgv;
if (Array.isArray(arguments[1])) { var options = {};
args = arguments[1]; var args = [];
options = util._extend({}, arguments[2]); var pos = 1;
} else if (arguments[1] && typeof arguments[1] !== 'object') { if (Array.isArray(arguments[pos])) {
throw new TypeError('Incorrect value of args option'); args = arguments[pos++];
} else { }
args = [];
options = util._extend({}, arguments[1]); 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: // Prepare arguments for fork:
Expand Down Expand Up @@ -132,7 +137,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
callback = arguments[pos++]; callback = arguments[pos++];
} }


if (pos === 1 && arguments.length > 1) { if (!callback && arguments[pos] != null) {
throw new TypeError('Incorrect value of args option'); throw new TypeError('Incorrect value of args option');
} }


Expand Down

0 comments on commit 0548e5d

Please sign in to comment.