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 <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
0268fd0a9f
commit
0548e5d12a
@ -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:
|
||||||
@ -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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user