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

child_process: add type checking for "args" param #8277

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ exports.execFile = function(file /* args, options, callback */) {
if (Array.isArray(arguments[1])) {
args = arguments[1];
options = util._extend(options, arguments[2]);
} else if (arguments[1] && callback !== arguments[1]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will still allow the same problematic behavior if the user passes in the empty string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll default the args to [] at that point; just tried this with child_process.spawn('echo', '').stdout.pipe(process.stdout); 1 and it doesn't seem to hang.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed in my testing that not all commands suffered from this problem. For example, ls and echo are fine. I was able to reproduce the original issue after pulling your changes locally and updating the command in your test file to read:

var c = execFile(process.execPath, '');

throw new TypeError(
"Parameter 'args' must be an array, not a " + typeof arguments[1]
);
} else {
args = [];
options = util._extend(options, arguments[1]);
Expand Down
39 changes: 39 additions & 0 deletions test/simple/test-child-process-string-args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
var execFile = require('child_process').execFile;
var err;

// path + string does not work.
try {
var c = execFile(process.execPath, 'string argument!');
} catch(e) {
err = e;
}
assert.ok(err);
assert.ok(err instanceof TypeError);

// path + callback still works
var c = execFile(process.execPath, function() {
});

c.kill('SIGINT');