Skip to content

Commit

Permalink
crypto: add check for funciton call fail scenario, add test case for …
Browse files Browse the repository at this point in the history
…the fix
  • Loading branch information
ThakurKarthik committed Sep 30, 2020
1 parent e138130 commit e8edcb5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/node_crypto.cc
Expand Up @@ -3467,7 +3467,9 @@ BaseObjectPtr<BaseObject> NativeKeyObject::KeyObjectTransferData::Deserialize(
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);
if (env->native_module_require()->
Call(context, Null(env->isolate()), 1, &arg).IsEmpty())
return {};
switch (data_->GetKeyType()) {
case kKeyTypeSecret:
key_ctor = env->crypto_key_object_secret_constructor();
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-crypto-worker-thread.js
@@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

// Issue https://github.com/nodejs/node/issues/35263
/* Description: test for checking keyobject passed to worker thread
does not crash */
const { createSecretKey } = require('crypto');

const { Worker, isMainThread, workerData } = require('worker_threads');

if (isMainThread) {
const key = createSecretKey(Buffer.from('hello'));
new Worker(__filename, { workerData: key });
} else {
console.log(workerData);
}

0 comments on commit e8edcb5

Please sign in to comment.