Skip to content

Commit 93ad3d6

Browse files
committed
quic: fix per-session SSL leak
Signed-off-by: Tim Perry <pimterry@gmail.com>
1 parent ea6ec93 commit 93ad3d6

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎src/quic/tlscontext.cc‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ OSSLContext::~OSSLContext() {
188188

189189
void OSSLContext::reset() {
190190
if (ctx_) {
191-
// The SSL object inside the ngtcp2 ctx may not have been set if
192-
// SSL creation failed. Guard against null before clearing app data.
193-
if (SSL* ssl = *this; ssl != nullptr) {
194-
SSL_set_app_data(ssl, nullptr);
191+
if (ssl_) {
192+
SSL_set_app_data(ssl_.get(), nullptr);
193+
ngtcp2_crypto_ossl_ctx_set_ssl(ctx_, nullptr);
194+
ssl_.reset();
195195
}
196196
// connection_ is set during Initialize(). If Initialize() was
197197
// never called (e.g. SSL creation failed), it's still nullptr.
@@ -205,19 +205,20 @@ void OSSLContext::reset() {
205205
}
206206

207207
OSSLContext::operator SSL*() const {
208-
return ngtcp2_crypto_ossl_ctx_get_ssl(ctx_);
208+
return ssl_.get();
209209
}
210210

211211
OSSLContext::operator ngtcp2_crypto_ossl_ctx*() const {
212212
return ctx_;
213213
}
214214

215-
void OSSLContext::Initialize(SSL* ssl,
215+
void OSSLContext::Initialize(SSLPointer ssl,
216216
ngtcp2_crypto_conn_ref* ref,
217217
ngtcp2_conn* connection,
218218
SSL_CTX* ssl_ctx) {
219219
CHECK(ssl);
220-
ngtcp2_crypto_ossl_ctx_set_ssl(ctx_, ssl);
220+
ssl_ = std::move(ssl);
221+
ngtcp2_crypto_ossl_ctx_set_ssl(ctx_, ssl_.get());
221222
SSL_set_app_data(*this, ref);
222223
// TODO(@jasnell): Later when BoringSSL is also supported, the native
223224
// handle will be different. The ngtcp2_crypto_ossl.h impl requires
@@ -894,7 +895,7 @@ void TLSSession::Initialize(
894895
EnableTrace(session_->env(), &bio_trace_, ssl);
895896
}
896897

897-
ossl_context_.Initialize(ssl.release(), &ref_, session(), ctx);
898+
ossl_context_.Initialize(std::move(ssl), &ref_, session(), ctx);
898899

899900
switch (ctx.side()) {
900901
case Side::SERVER: {

‎src/quic/tlscontext.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class OSSLContext final {
4141
operator SSL*() const;
4242
operator ngtcp2_crypto_ossl_ctx*() const;
4343

44-
void Initialize(SSL* ssl,
44+
void Initialize(ncrypto::SSLPointer ssl,
4545
ngtcp2_crypto_conn_ref* ref,
4646
ngtcp2_conn* connection,
4747
SSL_CTX* ssl_ctx);
@@ -73,6 +73,7 @@ class OSSLContext final {
7373
private:
7474
ngtcp2_crypto_ossl_ctx* ctx_;
7575
ngtcp2_conn* connection_ = nullptr;
76+
ncrypto::SSLPointer ssl_;
7677
};
7778

7879
// Every QUIC Session has exactly one TLSSession that maintains the state

0 commit comments

Comments
 (0)