Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 359a79d

Browse files
committedJun 27, 2016
child_process: validate fork/execFile arguments
Fixes: nodejs#2681 Refs: nodejs#4508
1 parent c0e48bf commit 359a79d

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)
Please sign in to comment.