check field length against remaining buffer in mysql Field::Parse#3381
Open
ubeddulla wants to merge 1 commit into
Open
check field length against remaining buffer in mysql Field::Parse#3381ubeddulla wants to merge 1 commit into
ubeddulla wants to merge 1 commit into
Conversation
Signed-off-by: ubeddulla khan <ubed@bugqore.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What problem does this PR solve?
Issue Number: resolve N/A
Problem Summary:
The text-protocol
MysqlReply::Field::Parseinsrc/brpc/policy/mysql/mysql_reply.cppreads a length-encoded field length from the server and callsbuf.cutn(&str, len)without checkinglenagainst the remaining buffer.IOBuf::cutnclamps to what is available, so a field whose length-encoded prefix claims more bytes than remain makes the string branch allocatelenarena bytes, copy only the fewer bytes actually present, and then publish_data.stras a StringPiece oflenbytes. The tail is uninitialized arena memory that gets read back by the caller, and the short read desyncs the packet stream. A malicious or compromised MySQL server can trigger it through any text result set. Every sibling length-encoded read in the same file (the binaryField::Parse,Column::Parse, the auth-plugin path,ParseBinaryTime/ParseBinaryDataTime) already rejectslen > buf.size(); only this text overload was missing the check.What is changed and the side effects?
Changed:
Added the same
len > buf.size()guard before thecutnin the textField::Parse, returningPARSE_ERROR_ABSOLUTELY_WRONGon an oversized length. Valid result sets are unaffected since a well-formed field always fits in the buffer.Side effects:
Performance effects: none, a single size comparison per field.
Breaking backward compatibility: none.
Check List: