bugfix(network): Prevent buffer overflow in NetPacket::readFileMessage() and NetPacket::readFileAnnounceMessage() #1981
+6
−16
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 a continuation of an earlier orphaned PR
Closes: #1668
This PR fixes two possible buffer overflows in NetPacket file handling messages.
We are expecting the received message to be in a particular format and for strings received to be null terminated.
But the original code never checked if we had exceeded the size of the buffer in which the string will be stored.
The size of the buffer cannot be changed as it relates to the maximum path length supported within windows when long file paths are not in use.
Strlcpy will return the length of the orginal string beyond the size of the buffer but will only copy up to the buffer size-1, the rest of the code is safe from malicious behaviour but a malformed packet may cause unexpected behaviour still.