Skip to content

Commit 0548e5d

Browse files
committed
child_process: add fork/execFile arg validation
Validate fork/execFile arguments. Fixes: #2681 Refs: #4508 PR-URL: #7399 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0268fd0 commit 0548e5d

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/child_process.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ const ChildProcess = exports.ChildProcess = child_process.ChildProcess;
1919
exports.fork = function(modulePath /*, args, options*/) {
2020

2121
// Get options and args arguments.
22-
var options, args, execArgv;
23-
if (Array.isArray(arguments[1])) {
24-
args = arguments[1];
25-
options = util._extend({}, arguments[2]);
26-
} else if (arguments[1] && typeof arguments[1] !== 'object') {
27-
throw new TypeError('Incorrect value of args option');
28-
} else {
29-
args = [];
30-
options = util._extend({}, arguments[1]);
22+
var execArgv;
23+
var options = {};
24+
var args = [];
25+
var pos = 1;
26+
if (Array.isArray(arguments[pos])) {
27+
args = arguments[pos++];
28+
}
29+
30+
if (arguments[pos] != null) {
31+
if (typeof arguments[pos] !== 'object') {
32+
throw new TypeError('Incorrect value of args option');
33+
} else {
34+
options = util._extend({}, arguments[pos++]);
35+
}
3136
}
3237

3338
// Prepare arguments for fork:
@@ -132,7 +137,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
132137
callback = arguments[pos++];
133138
}
134139

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

0 commit comments

Comments
 (0)