-
Notifications
You must be signed in to change notification settings - Fork 245
Guard GetValFromStream against out-of-bounds reads in release builds #3821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2832,6 +2832,14 @@ uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn, int& iPos, | |
| Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) ); | ||
| Q_ASSERT ( vecIn.Size() >= iPos + iNumOfBytes ); | ||
|
|
||
| // The asserts above are compiled out in release builds, so also guard at | ||
| // runtime: CVector uses unchecked operator[], and reading past the end of a | ||
| // truncated/malformed network message would be an out-of-bounds access. | ||
| if ( ( iNumOfBytes < 1 ) || ( iNumOfBytes > 4 ) || ( vecIn.Size() < iPos + iNumOfBytes ) ) | ||
| { | ||
| return 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the question what it should actually return...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is conflating an error indication with a fetched value. In my view, the correct fix would be for the This would require all calls within protocol.cpp to be reworked, but I think it's worth doing, and shouldn't take too long. I'm happy to take that on if agreed, Also, the runtime checks on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The data from the wire is definitely unchecked at the moment then?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like some values are checked, and others are just used without checking. |
||
| } | ||
|
|
||
| uint32_t iRet = 0; | ||
|
|
||
| for ( int i = 0; i < iNumOfBytes; i++ ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be removed...