Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: validate execFile & fork arguments #4508

Closed
wants to merge 2 commits into from

Conversation

ChuckLangford
Copy link
Contributor

The argument parsing for execFile and fork are inconsistent. execFile
throws on one invalid argument but not others. fork has similar logic
but the implementation is very different. This update implements
consistency for both functions.

Fixes: #2681

@jasnell

@silverwind silverwind added the child_process Issues and PRs related to the child_process subsystem. label Jan 1, 2016
@Trott
Copy link
Member

Trott commented Jan 1, 2016

CI: https://ci.nodejs.org/job/node-test-commit/1603/

If I'm not mistaken, this would be semver-major. I'm going to go ahead and label it as such. If you haven't already, you might want to check to make sure there aren't any doc files that would need to be updated.

@Trott Trott added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 1, 2016
@jasnell
Copy link
Member

jasnell commented Jan 4, 2016

LGTM if CI is green. Definitely semver-major

@ChuckLangford
Copy link
Contributor Author

@Trott: So I've never used Jenkins and I'm not familiar will all of the various builds for the Node project. Can you help me interpret the results of the build you linked to? Ideally, what are my next steps?

@jbergstroem
Copy link
Member

@ChuckLangford: If there are any fails during the test run you want to look at them and check if they are related (what part of the code/tests did you change? Is the fail relevant to this?). We're not quite at a full 'green run' just yet.

Walking through the errors:

@Trott
Copy link
Member

Trott commented Jan 5, 2016

@ChuckLangford Unfortunately for Node.js but fortunately for you, the failures in that CI run have nothing to do with your code. We're chipping away at the issues, but it's a long slog.... But it looks like your changes are totally fine as far as Jenkins is concerned.

@ChuckLangford
Copy link
Contributor Author

Thanks for the education @jbergstroem @Trott

The argument parsing for execFile and fork are inconsistent. execFile
throws on one invalid argument but not others. fork has similar logic
but the implementation is very different. This update implements
consistency for both functions.

Fixes: nodejs#2681
Updated tests caught an unused variable. Removed it.
@ChuckLangford
Copy link
Contributor Author

Just updated the code after rebasing my branch to the latest and running updated tests.

@Trott
Copy link
Member

Trott commented Jan 13, 2016

Hi, @ChuckLangford! I imagine your rebasing is indicative of a desire to see this land rather than languish.

Looks like we have just the one LGTM from @jasnell. For a semver-major change, I believe it either needs to be discussed by @nodejs/ctc or there needs to at least be a critical mass of their members giving the LGTM.

Anyone from CTC want to comment here or tag it ctc-agenda?

@@ -114,6 +109,82 @@ exports.exec = function(command /*, options, callback*/) {
opts.callback);
};

function normalizeArgsOptions(allArgs, defaultOption) {
var pos = 1, arrayPos = -1, objectPos = -1, args;
Copy link
Member

Choose a reason for hiding this comment

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

I think we're using let and const for new code these days, best switch where appropriate

@rvagg
Copy link
Member

rvagg commented Jan 13, 2016

I'm finding the normalizing logic very hard to follow, mainly because it's not clear what the variables are eventually used for. Perhaps a comment or two might help ease the denseness of this code?

options = util._extend({}, arguments[1]);
}

var opts = normalizeForkArgs(arguments, options);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need a normalizeForkArgs(), as this code is specific to fork(). If the logic needs to be tightened up, it can be done here. fork() is one of the simpler cases, as we only need to validate an optional array and an optional object.

@cjihrig
Copy link
Contributor

cjihrig commented Jan 13, 2016

I'm not opposed to improving argument checking, but I think this PR in its current form is too complex for what it actually buys us.

@ChuckLangford
Copy link
Contributor Author

Thanks so much for the feedback @cjihrig and @rvagg. If I understand correctly, you're both finding the code hard to follow and potentially difficult to maintain. This brings up a question I had while working on this code.

In general, does the Node project favor code that is verbose but easier to read/understand over code that is shorter but potentially confusing? I'm thinking you've both answered this question but just wanted to confirm.

@cjihrig
Copy link
Contributor

cjihrig commented Jan 13, 2016

In general, does the Node project favor code that is verbose but easier to read/understand over code that is shorter but potentially confusing? I'm thinking you've both answered this question but just wanted to confirm.

That is a loaded question. It depends. I think that, in general, simplicity, readability, and maintainability are valued. However, Node MUST be fast in a lot of situations, and there are plenty of places throughout core where sacrifices are made in the name of performance. The answer you get may vary depending on who answers it as well.

@rvagg
Copy link
Member

rvagg commented Jan 14, 2016

The answer you get may vary depending on who answers it as well.

This. There is no unified answer here and because we aim for general consensus amongst the collaborators who choose to weigh in on a different topic it's always going to be a back-and-forth to find a mid-point that is satisfactory. There are a lot of places in core that I could apply my comment about needing in-line comments, there are far too many obscure areas in core that are difficult to understand. But we don't do bulk-changes for the sake of the changes themselves, so it's one bit at a time.

@ChuckLangford
Copy link
Contributor Author

Thanks for all the feedback everyone. I'm closing this because the changes necessary to make this code more readable will look different enough to warrant a new PR.

Trott added a commit to Trott/io.js that referenced this pull request Jun 27, 2016
Trott added a commit to Trott/io.js that referenced this pull request Jun 30, 2016
Validate fork/execFile arguments.

Fixes: nodejs#2681
Refs: nodejs#4508
PR-URL: nodejs#7399
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Trott pushed a commit to Trott/io.js that referenced this pull request Jun 30, 2016
Fixes: nodejs#2681
Refs: nodejs#4508
PR-URL: nodejs#7399
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants