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

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

Conversation

chrisdickinson
Copy link

This commit ensures that the "args" parameter is either:

  1. Undefined or null (defaulting "args" to []).
  2. The callback parameter (defaulting "args" to []).
  3. An array.

All other values will throw a TypeError.

Fixes #8249.

This commit ensures that the "args" parameter is either:

1. Undefined or null (defaulting to []).
2. The callback parameter (defaulting to []).
3. An array.

All other values will throw a TypeError.

Fixes nodejs#8249.
@@ -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, '');

@jasnell
Copy link
Member

jasnell commented Aug 13, 2015

@chrisdickinson ... given that this was opened against v0.10, any reason to keep this open?

@jasnell
Copy link
Member

jasnell commented Aug 27, 2015

@chrisdickinson .. going to close this here. given the current status, there's really no reason to land this in v0.10.

@jasnell jasnell closed this Aug 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants