From e8edcb52fac6fb070a8c8fb84f7246666dfc7acb Mon Sep 17 00:00:00 2001 From: ThakurKarthik Date: Wed, 30 Sep 2020 22:54:25 +0530 Subject: [PATCH] crypto: add check for funciton call fail scenario, add test case for the fix --- src/node_crypto.cc | 4 +++- test/parallel/test-crypto-worker-thread.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-crypto-worker-thread.js diff --git a/src/node_crypto.cc b/src/node_crypto.cc index e2229fbe366a35..ed886abd749661 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3467,7 +3467,9 @@ BaseObjectPtr NativeKeyObject::KeyObjectTransferData::Deserialize( Local key_ctor; Local 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(); diff --git a/test/parallel/test-crypto-worker-thread.js b/test/parallel/test-crypto-worker-thread.js new file mode 100644 index 00000000000000..c3b978ceb3d37c --- /dev/null +++ b/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); +}