Skip to content

Commit

Permalink
Fix segmenatation fault if connection is closed during handshake (#399)
Browse files Browse the repository at this point in the history
Fixes #398

### Motivation

There is an implicit requirement for the `async_handshake` API that
before it's done, the `socket` and `ssl::stream` objects must exist.
Otherwise segmenatation fault might happen.

### Modifications

Capture `socket_` and `tlsSocket_` in the handshake callback. It can be
verified by modifying the code according to #398 and rerun the test.
  • Loading branch information
BewareMyPower authored Feb 6, 2024
1 parent 289c930 commit 71077b8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ClientConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ void ClientConnection::handleTcpConnected(const ASIO_ERROR& err, tcp::resolver::
}
}
auto weakSelf = weak_from_this();
auto callback = [weakSelf](const ASIO_ERROR& err) {
auto socket = socket_;
auto tlsSocket = tlsSocket_;
// socket and ssl::stream objects must exist until async_handshake is done, otherwise segmentation
// fault might happen
auto callback = [weakSelf, socket, tlsSocket](const ASIO_ERROR& err) {
auto self = weakSelf.lock();
if (self) {
self->handleHandshake(err);
Expand Down

0 comments on commit 71077b8

Please sign in to comment.