Skip to content

Commit 71077b8

Browse files
Fix segmenatation fault if connection is closed during handshake (#399)
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.
1 parent 289c930 commit 71077b8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/ClientConnection.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,11 @@ void ClientConnection::handleTcpConnected(const ASIO_ERROR& err, tcp::resolver::
456456
}
457457
}
458458
auto weakSelf = weak_from_this();
459-
auto callback = [weakSelf](const ASIO_ERROR& err) {
459+
auto socket = socket_;
460+
auto tlsSocket = tlsSocket_;
461+
// socket and ssl::stream objects must exist until async_handshake is done, otherwise segmentation
462+
// fault might happen
463+
auto callback = [weakSelf, socket, tlsSocket](const ASIO_ERROR& err) {
460464
auto self = weakSelf.lock();
461465
if (self) {
462466
self->handleHandshake(err);

0 commit comments

Comments
 (0)