Address invalid memory access (#104) in rdpClientCon #125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the last of a couple of pull requests to address the memory issues found in #104 by @keithrob91.
As mentioned in that request, the
clientCon
is freed wheneverrdpClientConSend()
orrdpClientConRecv()
detect a connection problem. Not all the code paths are expecting this, and as a result theclientCon
is potentially accessed after being freed.One approach would be to go through all the code paths which call
rdpClientConSend()
orrdpClientConRecv()
and check they can handle the connection being deleted. I think this is likely to be a bit fiddly and quite brittle to maintain.The approach I've taken is to remove most of the calls to
rdpClientConDisconnect()
and replace them with clearing a boolean flagconnected
. The actual call tordpClientConDisconnect()
now happens in the main select loop. This makes it a lot easier to check that the connection isn't accessed after being freed.Here are some other notes:-
struct _rdpClientCon
contained a couple of boolean members that were effectively serving no purpose. These wereconnected
andsckClosed
. I've repurposedconnected
to act as the marker above, and I've removedsckClosed
.rdpAddClientConToDev()
andrdpRemoveClientConFromDev()
@keithrob91 - would you be happy to run your static analysis tool again? I don't have access to anything better than cppcheck here.