Skip to content

Commit 238e801

Browse files
authored
Fix for Bug #36732 (#36879)
Set the app_state callback object in the Connection state to null when the CASE session object is being cleared, on top of setting the inner callback methods to null. This prevents the callback object from being accessed later, when the connection is getting closed(after the CASE session has been set up and the session object no longer exists).
1 parent 48e8a0e commit 238e801

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/protocols/secure_channel/CASESession.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,20 @@ void CASESession::Clear()
428428
mTCPConnCbCtxt.connClosedCb = nullptr;
429429
mTCPConnCbCtxt.connReceivedCb = nullptr;
430430

431-
if (mPeerConnState && mPeerConnState->mConnectionState != Transport::TCPState::kConnected)
431+
if (mPeerConnState)
432432
{
433-
// Abort the connection if the CASESession is being destroyed and the
434-
// connection is in the middle of being set up.
435-
mSessionManager->TCPDisconnect(mPeerConnState, /* shouldAbort = */ true);
436-
mPeerConnState = nullptr;
433+
// Set the app state callback object in the Connection state to null
434+
// to prevent any dangling pointer to memory(mTCPConnCbCtxt) owned
435+
// by the CASESession object, that is now getting cleared.
436+
mPeerConnState->mAppState = nullptr;
437+
438+
if (mPeerConnState->mConnectionState != Transport::TCPState::kConnected)
439+
{
440+
// Abort the connection if the CASESession is being destroyed and the
441+
// connection is in the middle of being set up.
442+
mSessionManager->TCPDisconnect(mPeerConnState, /* shouldAbort = */ true);
443+
mPeerConnState = nullptr;
444+
}
437445
}
438446
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
439447
}

0 commit comments

Comments
 (0)