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

src: use unique_ptr for requests in crypto #17000

Closed
wants to merge 1 commit into from

Conversation

fhinkel
Copy link
Member

@fhinkel fhinkel commented Nov 13, 2017

Instead of raw pointerns, use std::unique_ptr for PBKDF2Request and
RandomBytesRequest. This makes ownership more clear.

Checklist
Affected core subsystem(s)

src

@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 Nov 13, 2017
@@ -5533,9 +5533,9 @@ void PBKDF2Request::After() {

void PBKDF2Request::After(uv_work_t* work_req, int status) {
CHECK_EQ(status, 0);
PBKDF2Request* req = ContainerOf(&PBKDF2Request::work_req_, work_req);
std::unique_ptr<PBKDF2Request> req(
ContainerOf(&PBKDF2Request::work_req_, work_req));
Copy link
Member

Choose a reason for hiding this comment

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

4 space indent. (Line continuation.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I think I have a few of these wrong. Let me check my other PRs.

saltlen,
salt,
iter,
keylen));
Copy link
Member

Choose a reason for hiding this comment

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

Since you're here, I'd be okay with writing this as:

std::unique_ptr<PBKDF2Request> req(
    new PBKDF2Request(env, obj, digest, passlen, pass, saltlen, iter, keylen));

Instead of raw pointerns, use std::unique_ptr for PBKDF2Request and
RandomBytesRequest. This makes ownership more clear.
@fhinkel fhinkel force-pushed the nov/unique_ptr_crypto branch from 701d89c to e86545e Compare November 14, 2017 21:41
@fhinkel
Copy link
Member Author

fhinkel commented Nov 15, 2017

@fhinkel
Copy link
Member Author

fhinkel commented Nov 15, 2017

CI failures are unrelated. Landed in 1b093cb.

@fhinkel fhinkel closed this Nov 15, 2017
fhinkel added a commit that referenced this pull request Nov 15, 2017
Instead of raw pointerns, use std::unique_ptr for PBKDF2Request and
RandomBytesRequest. This makes ownership more clear.

PR-URL: #17000
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
fhinkel added a commit that referenced this pull request Nov 17, 2017
Add rule for smart pointers, i.e., std::unique_ptr and std::shared_ptr,
to the Cpp style guide. Mostly copied from the Google style guide.

PR-URL: #17055
Ref: #16970
Ref: #16974
Ref: #17000
Ref: #17012
Ref: #17020
Ref: #17030
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins pushed a commit that referenced this pull request Dec 11, 2017
Instead of raw pointerns, use std::unique_ptr for PBKDF2Request and
RandomBytesRequest. This makes ownership more clear.

PR-URL: #17000
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
Add rule for smart pointers, i.e., std::unique_ptr and std::shared_ptr,
to the Cpp style guide. Mostly copied from the Google style guide.

PR-URL: #17055
Ref: #16970
Ref: #16974
Ref: #17000
Ref: #17012
Ref: #17020
Ref: #17030
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Dec 12, 2017
@MylesBorins
Copy link
Contributor

This needs to be manually backported to v6.x and v8.x.

6.x does not have pbkdf2, but we might want to backport it in the next minor. Please leave the label on right now and we will revisit the 6.x backport in January

@gibfahn
Copy link
Member

gibfahn commented Dec 19, 2017

Compile failure on 8.x:

  g++ '-DNODE_ARCH="x64"' '-DNODE_PLATFORM="linux"' '-DNODE_WANT_INTERNALS=1' '-DV8_DEPRECATION_WARNINGS=1' '-DHAVE_INSPECTOR=1' '-D__POSIX__' '-DHAVE_OPENSSL=1' '-DNODE_USE_V8_PLATFORM=1' '-DNODE_HAVE_I18N_SUPPORT=1' '-DNODE_HAVE_SMALL_ICU=1' '-DNGHTTP2_STATICLIB' '-DUCONFIG_NO_SERVICE=1' '-DUCONFIG_NO_REGULAR_EXPRESSIONS=1' '-DU_ENABLE_DYLOAD=0' '-DU_STATIC_IMPLEMENTATION=1' '-DU_HAVE_STD_STRING=0' '-DUCONFIG_NO_BREAK_ITERATION=0' '-DHTTP_PARSER_STRICT=0' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-D_POSIX_C_SOURCE=200112' -I../src -I../tools/msvs/genfiles -I/build/gib/node/out/Release/obj/gen -I../deps/nghttp2/lib/includes -I/build/gib/node/out/Release/obj/gen/include -I../deps/openssl/openssl/include -I../deps/v8/include -I../deps/icu-small/source/i18n -I../deps/icu-small/source/common -I../deps/zlib -I../deps/http_parser -I../deps/cares/include -I../deps/uv/include  -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF /build/gib/node/out/Release/.deps//build/gib/node/out/Release/obj.target/node/src/tls_wrap.o.d.raw   -c -o /build/gib/node/out/Release/obj.target/node/src/tls_wrap.o ../src/tls_wrap.cc
../src/node_contextify.cc: In static member function ‘static void node::{anonymous}::ContextifyContext::RunInDebugContext(const v8::FunctionCallbackInfo<v8::Value>&)’:
../src/node_contextify.cc:278:76: warning: ‘static v8::Local<v8::Context> v8::Debug::GetDebugContext(v8::Isolate*)’ is deprecated (declared at ../deps/v8/include/v8-debug.h:208): Use v8-inspector [-Wdeprecated-declarations]
     Local<Context> debug_context = Debug::GetDebugContext(args.GetIsolate());
                                                                            ^
../src/node_contextify.cc:283:75: warning: ‘static bool v8::Debug::SetDebugEventListener(v8::Isolate*, v8::Debug::EventCallback, v8::Local<v8::Value>)’ is deprecated (declared at ../deps/v8/include/v8-debug.h:145): No longer supported [-Wdeprecated-declarations]
       Debug::SetDebugEventListener(args.GetIsolate(), dummy_event_listener);
                                                                           ^
../src/node_contextify.cc:284:63: warning: ‘static v8::Local<v8::Context> v8::Debug::GetDebugContext(v8::Isolate*)’ is deprecated (declared at ../deps/v8/include/v8-debug.h:208): Use v8-inspector [-Wdeprecated-declarations]
       debug_context = Debug::GetDebugContext(args.GetIsolate());
                                                               ^
../src/node_crypto.cc: In function ‘void node::crypto::PBKDF2(const v8::FunctionCallbackInfo<v8::Value>&)’:
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5437:12: error:   from here [-fpermissive]
       goto err;
            ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5427:10: error:   from here [-fpermissive]
     goto err;
          ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5420:10: error:   from here [-fpermissive]
     goto err;
          ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5415:10: error:   from here [-fpermissive]
     goto err;
          ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5409:10: error:   from here [-fpermissive]
     goto err;
          ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5401:10: error:   from here [-fpermissive]
     goto err;
          ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5390:10: error:   from here [-fpermissive]
     goto err;
          ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node_crypto.cc:5478:2: error: jump to label ‘err’ [-fpermissive]
  err:
  ^
../src/node_crypto.cc:5383:10: error:   from here [-fpermissive]
     goto err;
          ^
../src/node_crypto.cc:5447:34: error:   crosses initialization of ‘std::unique_ptr<node::crypto::PBKDF2Request> req’
   std::unique_ptr<PBKDF2Request> req(
                                  ^
../src/node.cc: In function ‘void node::DebugPause(const v8::FunctionCallbackInfo<v8::Value>&)’:
../src/node.cc:4422:42: warning: ‘static void v8::Debug::DebugBreak(v8::Isolate*)’ is deprecated (declared at ../deps/v8/include/v8-debug.h:151): No longer supported [-Wdeprecated-declarations]
   v8::Debug::DebugBreak(args.GetIsolate());
                                          ^

gibfahn pushed a commit that referenced this pull request Dec 19, 2017
Add rule for smart pointers, i.e., std::unique_ptr and std::shared_ptr,
to the Cpp style guide. Mostly copied from the Google style guide.

PR-URL: #17055
Ref: #16970
Ref: #16974
Ref: #17000
Ref: #17012
Ref: #17020
Ref: #17030
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
Add rule for smart pointers, i.e., std::unique_ptr and std::shared_ptr,
to the Cpp style guide. Mostly copied from the Google style guide.

PR-URL: #17055
Ref: #16970
Ref: #16974
Ref: #17000
Ref: #17012
Ref: #17020
Ref: #17030
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@jasnell
Copy link
Member

jasnell commented Aug 17, 2018

i'm not convinced this is worth backporting to 8.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

8 participants