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

crypto: set env values in Deserialize method by calling CreateNativeK… #35416

Closed
wants to merge 2 commits into from

Conversation

ThakurKarthik
Copy link
Contributor

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. labels Sep 29, 2020
Copy link
Member

@addaleax addaleax left a 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 :)

@@ -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);
Copy link
Member

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:

Suggested change
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 {};

Copy link
Contributor Author

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.

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 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. :)

@ThakurKarthik
Copy link
Contributor Author

Hi @addaleax I have added the requested changes. Please verify. Thanks !

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Nice, thank you :)

@addaleax addaleax added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. review wanted PRs that need reviews. labels Sep 30, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 30, 2020
@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax added commit-queue Add this label to land a pull request using GitHub Actions. and removed review wanted PRs that need reviews. labels Oct 3, 2020
@github-actions github-actions bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Oct 3, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2020

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

@addaleax
Copy link
Member

addaleax commented Oct 3, 2020

Landed in a8556da, thanks for the PR! 🎉

@addaleax addaleax closed this Oct 3, 2020
addaleax pushed a commit that referenced this pull request Oct 3, 2020
Fixes: #35263

PR-URL: #35416
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@jasnell
Copy link
Member

jasnell commented Oct 4, 2020

Woo! Thank you @ThakurKarthik !

danielleadams pushed a commit that referenced this pull request Oct 6, 2020
Fixes: #35263

PR-URL: #35416
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@danielleadams danielleadams mentioned this pull request Oct 6, 2020
MylesBorins pushed a commit that referenced this pull request Nov 3, 2020
Fixes: #35263

PR-URL: #35416
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Nov 3, 2020
MylesBorins pushed a commit that referenced this pull request Nov 16, 2020
Fixes: #35263

PR-URL: #35416
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
joesepi pushed a commit to joesepi/node that referenced this pull request Jan 8, 2021
Fixes: nodejs#35263

PR-URL: nodejs#35416
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@targos targos removed the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

workers, crypto: passing KeyObject as workerData crashes
6 participants