Skip to content

Commit e378906

Browse files
committed
Handle JS getter exceptions in GetSSLCtx
1 parent b316884 commit e378906

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/crypto/crypto_context.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,9 @@ NODE_EXTERN SSL_CTX* GetSSLCtx(Local<Context> context, Local<Value> value) {
24472447
Environment* env = Environment::GetCurrent(context);
24482448
if (env == nullptr) return nullptr;
24492449

2450+
// TryCatchto swallow any exceptions from Get() (e.g. failing getters)
2451+
v8::TryCatch try_catch(env->isolate());
2452+
24502453
// Unwrap the .context property from the JS SecureContext wrapper
24512454
// (as returned by tls.createSecureContext()).
24522455
if (value->IsObject()) {

test/addons/openssl-get-ssl-ctx/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ const binding = require(`./build/${common.buildType}/binding`);
3838
{
3939
assert.strictEqual(binding.getSSLCtxInvalid({ context: 'not a context' }), true);
4040
}
41+
42+
// Test 7: An object with a throwing .context getter should return nullptr
43+
// without propagating the exception.
44+
{
45+
const obj = {
46+
get context() { throw new Error('getter threw'); },
47+
};
48+
assert.strictEqual(binding.getSSLCtxInvalid(obj), true);
49+
}

0 commit comments

Comments
 (0)