-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
crypto: set env values in Deserialize method by calling CreateNativeK… #35416
Conversation
Review requested:
|
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.
This is definitely a five-star first contribution 👍
I think ideally we’d also add a test here (for example so that nobody attempts to remove the extra require()
call here), which you could probably base on the test case that @jasnell provided in the original issue :)
src/node_crypto.cc
Outdated
@@ -3466,6 +3465,9 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize( | |||
|
|||
Local<Value> handle = KeyObjectHandle::Create(env, data_).ToLocalChecked(); | |||
Local<Function> key_ctor; | |||
Local<Value> arg = FIXED_ONE_BYTE_STRING(env->isolate(), | |||
"internal/crypto/keys"); | |||
env->native_module_require()->Call(context, Null(env->isolate()), 1, &arg); |
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.
This call here could fail to populate env->crypto_key_object_secret_constructor()
etc., mostly because the existence of worker.terminate()
means that any call into JS can fail with an exception, regardless of whether the code itself throws something or not.
So I would recommend checking for an exception here, and returning if there is one:
env->native_module_require()->Call(context, Null(env->isolate()), 1, &arg); | |
if (env->native_module_require()->Call(context, Null(env->isolate()), 1, &arg).IsEmpty()) | |
return {}; |
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 i will incorporate this check, how should i proceed with writing a test for these changes? jasnell said he added a check in his open draft pull request. Looks like as part of refactoring, node_crypto.cc file is removed over 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.
I think you could basically take the snipped from the issue, add a require('../common');
as the first statement, and maybe a comment that links to the issue, and then just save that as a file in test/parallel/
.
Looks like as part of refactoring, node_crypto.cc file is removed over there.
I think that PR might require a rebase or two anyway. Also, this PR should probably land at least on v14.x and v12.x as well, unlike the other one, so the backporting process is easier overall if this PR lands on its own and we don’t worry as much about the other one. :)
71ae739
to
e8edcb5
Compare
Hi @addaleax I have added the requested changes. Please verify. 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.
Nice, thank you :)
Commit Queue failed- Loading data for nodejs/node/pull/35416 ✔ Done loading data for nodejs/node/pull/35416 ----------------------------------- PR info ------------------------------------ Title crypto: set env values in Deserialize method by calling CreateNativeK… (#35416) Author Thakur Karthik (@ThakurKarthik, first-time contributor) Branch ThakurKarthik:karthik-dev -> nodejs:master Labels C++, author ready, crypto Commits 2 - crypto: set env values in Deserialize method by calling CreateNativeK… - crypto: add check for funciton call fail scenario, add test case for … Committers 1 - ThakurKarthik PR-URL: https://github.com/nodejs/node/pull/35416 Fixes: https://github.com/nodejs/node/issues/35263 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/35416 Fixes: https://github.com/nodejs/node/issues/35263 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott -------------------------------------------------------------------------------- ✖ Last GitHub CI failed ℹ Last Full PR CI on 2020-09-30T18:23:16Z: https://ci.nodejs.org/job/node-test-pull-request/33305/ - Querying data for job/node-test-pull-request/33305/ ✔ Build data downloaded ✔ Last Jenkins CI successful ℹ This PR was created on Tue, 29 Sep 2020 15:34:45 GMT ✔ Approvals: 2 ✔ - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/35416#pullrequestreview-499689022 ✔ - Rich Trott (@Trott) (TSC): https://github.com/nodejs/node/pull/35416#pullrequestreview-501546639 -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncu |
Landed in a8556da, thanks for the PR! 🎉 |
Woo! Thank you @ThakurKarthik ! |
Fixes: nodejs#35263 PR-URL: nodejs#35416 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
Hi @addaleax @jasnell I added some changes for the issue, I verified in my system the example jasnell has posted earlier, it is not throwing any segmentation fault. Please review the changes.Thanks !
Fixes: #35263
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes