Skip to content

Commit bc19d1f

Browse files
committed
Fix data race in SSLCertContext copy & assignment
Resolve concurrent read/write data races by using std::scoped_lock in operator= and locking other.ctx_mutex at the start of the copy constructor.
1 parent e79182f commit bc19d1f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/iocore/net/SSLCertLookup.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,24 @@ ssl_create_ticket_keyblock(const char *ticket_key_path)
234234

235235
SSLCertContext::SSLCertContext(SSLCertContext const &other)
236236
{
237+
std::shared_lock lock(other.ctx_mutex);
237238
opt = other.opt;
238239
userconfig = other.userconfig;
239240
keyblock = other.keyblock;
240241
ctx_type = other.ctx_type;
241-
std::shared_lock lock(other.ctx_mutex);
242-
ctx = other.ctx;
242+
ctx = other.ctx;
243243
}
244244

245245
SSLCertContext &
246246
SSLCertContext::operator=(SSLCertContext const &other)
247247
{
248248
if (&other != this) {
249+
std::scoped_lock lock(this->ctx_mutex, other.ctx_mutex);
249250
this->opt = other.opt;
250251
this->userconfig = other.userconfig;
251252
this->keyblock = other.keyblock;
252253
this->ctx_type = other.ctx_type;
253-
std::shared_lock lock(other.ctx_mutex);
254-
this->ctx = other.ctx;
254+
this->ctx = other.ctx;
255255
}
256256
return *this;
257257
}

0 commit comments

Comments
 (0)