Skip to content

Commit 0d23ac5

Browse files
authored
fix(tls): leak BIO_METHOD singleton to avoid use-after-free at exit (#1503)
Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
1 parent e7c182a commit 0d23ac5

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

net/security-context/tls-stream.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,8 @@ class TLSSocketStream : public ForwardSocketStream {
392392

393393
#endif
394394

395-
struct BIOMethodDeleter {
396-
void operator()(BIO_METHOD* ptr) { BIO_meth_free(ptr); }
397-
};
398-
399395
static BIO_METHOD* BIO_s_sockstream() {
400-
static std::unique_ptr<BIO_METHOD, BIOMethodDeleter> meth([] {
396+
static BIO_METHOD* const meth = [] {
401397
auto m = BIO_meth_new(BIO_TYPE_SOURCE_SINK, "BIO_PHOTON_SOCKSTREAM");
402398
BIO_meth_set_write(m, &TLSSocketStream::ssbio_bwrite);
403399
BIO_meth_set_read(m, &TLSSocketStream::ssbio_bread);
@@ -406,8 +402,8 @@ class TLSSocketStream : public ForwardSocketStream {
406402
BIO_meth_set_create(m, &TLSSocketStream::ssbio_create);
407403
BIO_meth_set_destroy(m, &TLSSocketStream::ssbio_destroy);
408404
return m;
409-
}());
410-
return meth.get();
405+
}();
406+
return meth;
411407
}
412408

413409
static ISocketStream* get_bio_sockstream(BIO* b) {

0 commit comments

Comments
 (0)