Skip to content

Commit b54cbfc

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 b54cbfc

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/iocore/net/SSLCertLookup.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "P_SSLUtils.h"
3535

3636
#include <mutex>
37+
#include <shared_mutex>
3738
#include <unordered_map>
3839
#include <utility>
3940
#include <vector>
@@ -234,24 +235,24 @@ ssl_create_ticket_keyblock(const char *ticket_key_path)
234235

235236
SSLCertContext::SSLCertContext(SSLCertContext const &other)
236237
{
238+
std::shared_lock lock(other.ctx_mutex);
237239
opt = other.opt;
238240
userconfig = other.userconfig;
239241
keyblock = other.keyblock;
240242
ctx_type = other.ctx_type;
241-
std::shared_lock lock(other.ctx_mutex);
242-
ctx = other.ctx;
243+
ctx = other.ctx;
243244
}
244245

245246
SSLCertContext &
246247
SSLCertContext::operator=(SSLCertContext const &other)
247248
{
248249
if (&other != this) {
250+
std::scoped_lock lock(this->ctx_mutex, other.ctx_mutex);
249251
this->opt = other.opt;
250252
this->userconfig = other.userconfig;
251253
this->keyblock = other.keyblock;
252254
this->ctx_type = other.ctx_type;
253-
std::shared_lock lock(other.ctx_mutex);
254-
this->ctx = other.ctx;
255+
this->ctx = other.ctx;
255256
}
256257
return *this;
257258
}

0 commit comments

Comments
 (0)