Skip to content

Commit

Permalink
Fix use after free in HTTPS listener on non-windows.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ras0219-msft committed Mar 5, 2016
1 parent 5f75ec9 commit ef8e748
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Release/include/cpprest/details/http_server_asio.h
Expand Up @@ -72,6 +72,7 @@ class connection
bool m_chunked;
std::atomic<int> m_refs; // track how many threads are still referring to this

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

public:
Expand All @@ -85,9 +86,11 @@ class connection
{
if (is_https)
{
boost::asio::ssl::context ssl_context(boost::asio::ssl::context::sslv23);
ssl_context_callback(ssl_context);
m_ssl_stream = utility::details::make_unique<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>(*m_socket, ssl_context);
m_ssl_context = utility::details::make_unique<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);
ssl_context_callback(*m_ssl_context);
m_ssl_stream = utility::details::make_unique<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>(*m_socket, *m_ssl_context);
m_ssl_stream = utility::details::make_unique<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>(*m_socket, *m_ssl_context);

m_ssl_stream->async_handshake(boost::asio::ssl::stream_base::server, [this](const boost::system::error_code&) { this->start_request_response(); });
}
else
Expand Down

0 comments on commit ef8e748

Please sign in to comment.