-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: check accessing a null stderr #6877
Conversation
LGTM |
execSync('exit -1', {shell: 'no_shell'}); | ||
}, /spawnSync no_shell ENOENT/); | ||
})(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: Why the closure? If just for scope maybe use block scope. Also we prefer arrow functions (I guess)
{
assert.throws(() => {
execSync('exit -1', {shell: 'no_shell'});
}, /spawnSync no_shell ENOENT/);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with Node.js code, so just copied the test from the end of this file and modified to thi particular use case.
But I can edit the comit and use your suggestion.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it's okay then. Don't bother.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't even need the closure at all I think?
(Should probably be fixed before landing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a similar test further down below. This new test should probably be added there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...that and I guess everyone before just copy-pasted tests, which is why the closure has propagated :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is a similar test down below, but I put this test the first one, because it has to be ran before other calls to execSync.
For example, if the below test, with timeout, is ran before the one added in this patch, it could throw another exception, masking the real one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow your logic. If any test in this file fails the test runner marks it as failed. I don't see where exception masking comes in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the actual exception is masked, the one who runs the test won't be able to easily identify the problem.
If I move this test at the end, then there is no reason for adding it, since the first test will clearly fail.
The problem with accessing a null stderr is that the test with timeout will:
- fail in ETIMEOUT assert, this way err won't be assigned
- in it's finally clause, the assert for err.status will also throw another exception, since err is null
The test will fail telling that it cannot access the 'status' of an undefined member at "assert(err.status > 128 || err.signal)", which apparently appears to be a problem in the test itself.
|
LGTM but agree that the test should be cleaned up a bit. |
I cleaned the test as suggested. Should I also clean the similar test from the end of this test file in this patch too? |
LGTM with a question: #6877 (comment)
No, that's fine. Let's see what the CI says: https://ci.nodejs.org/job/node-test-pull-request/2711/ |
CI one more time: https://ci.nodejs.org/job/node-test-pull-request/2936/ |
@@ -489,7 +489,7 @@ function execFileSync(/*command, args, options*/) { | |||
|
|||
var ret = spawnSync(opts.file, opts.args.slice(1), opts.options); | |||
|
|||
if (inheritStderr) | |||
if (inheritStderr && ret.stderr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test doesn't catch this one.
LGTM minus the missing test. I will say error output when the test fails isn't the best, it could perhaps use a message parameter. |
ping @robertchiras |
@Fishrock123 sorry for my late response. I was gone, without access to a PC. |
@robertchiras You also need a test for As for message, you may want to add a message argument as per the docs for |
ping @robertchiras |
a6e6b6f
to
2c1c798
Compare
@Fishrock123 sorry for the long delay. I updated the test according to your suggestions. |
If something bad happens in spawnSync, stderr might be null. Therefore, we have to check it before using it, so we won't mask the actual exception. Signed-off-by: Robert Chiras <[email protected]>
@robertchiras One last thing. The commits don't reflect your GitHub account. You might want to follow these steps https://help.github.com/articles/setting-your-username-in-git/ |
@robertchiras Mind updating your Git info for the commits? When you do I'll land this. :) $ git config --global user.email "[email protected]"
$ git config --global user.name "J. Random User" Then $ git commit --amend --reset-author
$ git push origin head --force |
Hi @Fishrock123: I already had my git config set up. I did it again and pushed the changes. What do you see wrong in my commit that do not reflect my Github account? Thanks! |
Exercise the call to execSync with a bad shell passed through options. Verify that the right exception is thrown. Signed-off-by: Robert Chiras <[email protected]>
@robertchiras You need to add the email address you have setup in git to your GitHub profile: https://github.com/settings/emails |
I used my work email address, probably this is why it didn't saw that it was me. I updated my work email account on Github. Now it should look good. |
If something bad happens in spawnSync, stderr might be null. Therefore, we have to check it before using it, so we won't mask the actual exception. PR-URL: #6877 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Jefe Lindstädt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
Thanks! Landed in 765de1a 🎉 :D |
If something bad happens in spawnSync, stderr might be null. Therefore, we have to check it before using it, so we won't mask the actual exception. PR-URL: #6877 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Jefe Lindstädt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This change is causing tests to fail on v4.x-staging. Is this something we should be putting time into getting working on v4.x? |
@thealphanerd, sorry for the late response. |
@robertchiras This is the error I am getting
|
@robertchiras the v4.x-staging branch is working fine for me without this fix applied. What OS are you on? |
Sorry, but for some reason, I assumed that my patch is already in v4.x-staging. I applied it and saw the issue. |
If something bad happens in spawnSync, stderr might be null. Therefore, we have to check it before using it, so we won't mask the actual exception. PR-URL: nodejs#6877 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Jefe Lindstädt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
If something bad happens in spawnSync, stderr might be null. Therefore, we have to check it before using it, so we won't mask the actual exception. Ref: #9152 PR-URL: #6877 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Jefe Lindstädt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
If something bad happens in spawnSync, stderr might be null. Therefore, we have to check it before using it, so we won't mask the actual exception. Ref: #9152 PR-URL: #6877 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Jefe Lindstädt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
Checklist
Affected core subsystem(s)
child_process, test
Description of change
Fix for child_process when accessing a null stderr and addition test path to exercise this false path.