Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8ee4810

Browse filesBrowse files
addaleaxtargos
authored andcommitted
src: pass along errors from KeyObject instantiation
PR-URL: #25734 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
1 parent ced4e71 commit 8ee4810
Copy full SHA for 8ee4810

File tree

Expand file treeCollapse file tree

2 files changed

+21
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-20
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+18-17Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,15 +3302,18 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
33023302
return function;
33033303
}
33043304

3305-
Local<Object> KeyObject::Create(Environment* env,
3306-
KeyType key_type,
3307-
const ManagedEVPPKey& pkey) {
3305+
MaybeLocal<Object> KeyObject::Create(Environment* env,
3306+
KeyType key_type,
3307+
const ManagedEVPPKey& pkey) {
33083308
CHECK_NE(key_type, kKeyTypeSecret);
33093309
Local<Value> type = Integer::New(env->isolate(), key_type);
3310-
Local<Object> obj =
3311-
env->crypto_key_object_constructor()->NewInstance(env->context(),
3312-
1, &type)
3313-
.ToLocalChecked();
3310+
Local<Object> obj;
3311+
if (!env->crypto_key_object_constructor()
3312+
->NewInstance(env->context(), 1, &type)
3313+
.ToLocal(&obj)) {
3314+
return MaybeLocal<Object>();
3315+
}
3316+
33143317
KeyObject* key = Unwrap<KeyObject>(obj);
33153318
CHECK(key);
33163319
if (key_type == kKeyTypePublic)
@@ -5798,24 +5801,22 @@ class GenerateKeyPairJob : public CryptoJob {
57985801
if (public_key_encoding_.output_key_object_) {
57995802
// Note that this has the downside of containing sensitive data of the
58005803
// private key.
5801-
*pubkey = KeyObject::Create(env, kKeyTypePublic, pkey_);
5804+
if (!KeyObject::Create(env, kKeyTypePublic, pkey_).ToLocal(pubkey))
5805+
return false;
58025806
} else {
5803-
MaybeLocal<Value> maybe_pubkey =
5804-
WritePublicKey(env, pkey_.get(), public_key_encoding_);
5805-
if (maybe_pubkey.IsEmpty())
5807+
if (!WritePublicKey(env, pkey_.get(), public_key_encoding_)
5808+
.ToLocal(pubkey))
58065809
return false;
5807-
*pubkey = maybe_pubkey.ToLocalChecked();
58085810
}
58095811

58105812
// Now do the same for the private key.
58115813
if (private_key_encoding_.output_key_object_) {
5812-
*privkey = KeyObject::Create(env, kKeyTypePrivate, pkey_);
5814+
if (!KeyObject::Create(env, kKeyTypePrivate, pkey_).ToLocal(privkey))
5815+
return false;
58135816
} else {
5814-
MaybeLocal<Value> maybe_privkey =
5815-
WritePrivateKey(env, pkey_.get(), private_key_encoding_);
5816-
if (maybe_privkey.IsEmpty())
5817+
if (!WritePrivateKey(env, pkey_.get(), private_key_encoding_)
5818+
.ToLocal(privkey))
58175819
return false;
5818-
*privkey = maybe_privkey.ToLocalChecked();
58195820
}
58205821

58215822
return true;
Collapse file

‎src/node_crypto.h‎

Copy file name to clipboardExpand all lines: src/node_crypto.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ class KeyObject : public BaseObject {
442442
static v8::Local<v8::Function> Initialize(Environment* env,
443443
v8::Local<v8::Object> target);
444444

445-
static v8::Local<v8::Object> Create(Environment* env,
446-
KeyType type,
447-
const ManagedEVPPKey& pkey);
445+
static v8::MaybeLocal<v8::Object> Create(Environment* env,
446+
KeyType type,
447+
const ManagedEVPPKey& pkey);
448448

449449
// TODO(tniessen): track the memory used by OpenSSL types
450450
SET_NO_MEMORY_INFO()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.