Skip to content

Commit 7bd587e

Browse files
committed
src: use BaseObjectPtr to store SNI context
Rather than relying on a link to the JS object, store a pointer to the C++ object directly. PR-URL: #30548 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 0b0f023 commit 7bd587e

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/node_crypto.cc

+9-3
Original file line numberDiff line numberDiff line change
@@ -2991,9 +2991,15 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) {
29912991
goto fire_cb;
29922992

29932993
if (cons->HasInstance(ctx)) {
2994-
SecureContext* sc;
2995-
ASSIGN_OR_RETURN_UNWRAP(&sc, ctx.As<Object>());
2996-
w->sni_context_.Reset(env->isolate(), ctx);
2994+
SecureContext* sc = Unwrap<SecureContext>(ctx.As<Object>());
2995+
CHECK_NOT_NULL(sc);
2996+
// XXX: There is a method w->SetSNIContext(sc), and you might think that
2997+
// it makes sense to call that here and make setting w->sni_context_ part
2998+
// of it. In fact, that passes the test suite, although SetSNIContext()
2999+
// performs a lot more operations.
3000+
// If anybody is familiar enough with the TLS code to know whether it makes
3001+
// sense, please do so or document why it doesn't.
3002+
w->sni_context_ = BaseObjectPtr<SecureContext>(sc);
29973003

29983004
int rv;
29993005

src/node_crypto.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class SSLWrap {
310310
ClientHelloParser hello_parser_;
311311

312312
v8::Global<v8::ArrayBufferView> ocsp_response_;
313-
v8::Global<v8::Value> sni_context_;
313+
BaseObjectPtr<SecureContext> sni_context_;
314314

315315
friend class SecureContext;
316316
};

src/tls_wrap.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,9 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
10651065
return SSL_TLSEXT_ERR_NOACK;
10661066
}
10671067

1068-
p->sni_context_.Reset(env->isolate(), ctx);
1069-
10701068
SecureContext* sc = Unwrap<SecureContext>(ctx.As<Object>());
10711069
CHECK_NOT_NULL(sc);
1070+
p->sni_context_ = BaseObjectPtr<SecureContext>(sc);
10721071
p->SetSNIContext(sc);
10731072
return SSL_TLSEXT_ERR_OK;
10741073
}

0 commit comments

Comments
 (0)