Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 70dafa7

Browse files
sam-githubtrevnorris
authored andcommitted
child_process: check fork args is an array
Optional fork args should be type-checked with same behaviour as the equivalent argument to spawn. PR-URL: #8454 Reviewed-by: Trevor Norris <[email protected]>
1 parent e17c5a7 commit 70dafa7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/child_process.js

+2
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ exports.fork = function(modulePath /*, args, options*/) {
525525
if (Array.isArray(arguments[1])) {
526526
args = arguments[1];
527527
options = util._extend({}, arguments[2]);
528+
} else if (arguments[1] && typeof arguments[1] !== 'object') {
529+
throw new TypeError('Incorrect value of args option');
528530
} else {
529531
args = [];
530532
options = util._extend({}, arguments[1]);

test/simple/test-child-process-spawn-typeerror.js

+11
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
var assert = require('assert');
2323
var child_process = require('child_process');
2424
var spawn = child_process.spawn;
25+
var fork = child_process.fork;
2526
var execFile = child_process.execFile;
2627
var cmd = (process.platform === 'win32') ? 'dir' : 'ls';
28+
var empty = require('../common').fixturesDir + '/empty.js';
2729

2830

2931
// verify that args argument must be an array
@@ -45,3 +47,12 @@ assert.throws(function() {
4547
assert.doesNotThrow(function() {
4648
execFile(cmd, {});
4749
});
50+
51+
// verify that fork has same argument parsing behaviour as spawn
52+
assert.throws(function() {
53+
fork(empty, 'this is not an array');
54+
}, TypeError);
55+
56+
assert.doesNotThrow(function() {
57+
execFile(empty, {});
58+
});

0 commit comments

Comments
 (0)