Skip to content

Commit ef8e748

Browse files
committed
Fix use after free in HTTPS listener on non-windows.
The boost examples for ssl::stream all use stack allocated contexts and streams; considering that the ssl::context is noncopyable, it seems that its lifetime must exceed any streams.
1 parent 5f75ec9 commit ef8e748

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Release/include/cpprest/details/http_server_asio.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class connection
7272
bool m_chunked;
7373
std::atomic<int> m_refs; // track how many threads are still referring to this
7474

75+
std::unique_ptr<boost::asio::ssl::context> m_ssl_context;
7576
std::unique_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>> m_ssl_stream;
7677

7778
public:
@@ -85,9 +86,11 @@ class connection
8586
{
8687
if (is_https)
8788
{
88-
boost::asio::ssl::context ssl_context(boost::asio::ssl::context::sslv23);
89-
ssl_context_callback(ssl_context);
90-
m_ssl_stream = utility::details::make_unique<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>(*m_socket, ssl_context);
89+
m_ssl_context = utility::details::make_unique<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);
90+
ssl_context_callback(*m_ssl_context);
91+
m_ssl_stream = utility::details::make_unique<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>(*m_socket, *m_ssl_context);
92+
m_ssl_stream = utility::details::make_unique<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>(*m_socket, *m_ssl_context);
93+
9194
m_ssl_stream->async_handshake(boost::asio::ssl::stream_base::server, [this](const boost::system::error_code&) { this->start_request_response(); });
9295
}
9396
else

0 commit comments

Comments
 (0)