If a client runs a shell command and then disconnects before the command completes, the CShellSock::m_pClient will become stale. Later, in CShellSock::ReadLine, this stale pointer will be used after being freed.
I solved this in my own implementation by overriding OnClientDisconnect in CShellMod, in which I issue CShellSock::Kill for all shell sockets owned by a particular client, and then set their m_pClients to NULL. If that field is NULL in CShellSock::ReadLine, any data read is discarded. (Killing the process behind the socket won't empty the socket, so we have to make sure we drop data that made it in)
If a client runs a shell command and then disconnects before the command completes, the CShellSock::m_pClient will become stale. Later, in CShellSock::ReadLine, this stale pointer will be used after being freed.
I solved this in my own implementation by overriding OnClientDisconnect in CShellMod, in which I issue CShellSock::Kill for all shell sockets owned by a particular client, and then set their m_pClients to NULL. If that field is NULL in CShellSock::ReadLine, any data read is discarded. (Killing the process behind the socket won't empty the socket, so we have to make sure we drop data that made it in)
## <bountysource-plugin>
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/2475192-use-after-free-in-shell-module?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github).
</bountysource-plugin>
<!-- github-sync-id:34847897 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
If a client runs a shell command and then disconnects before the command completes, the CShellSock::m_pClient will become stale. Later, in CShellSock::ReadLine, this stale pointer will be used after being freed.
I solved this in my own implementation by overriding OnClientDisconnect in CShellMod, in which I issue CShellSock::Kill for all shell sockets owned by a particular client, and then set their m_pClients to NULL. If that field is NULL in CShellSock::ReadLine, any data read is discarded. (Killing the process behind the socket won't empty the socket, so we have to make sure we drop data that made it in)
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Pull request?
Fixed in #1248