Repository navigation
Close socket on partial reply - #3005
Merged
Merged
Conversation
When a read fails or times out in the middle of a reply, the rest of the reply can still arrive. If the socket stays open, the next command reads it as its own reply and the connection stays out of step. Disconnect wherever we give up before the end of a reply, the same way redis_sock_gets() already does: * a short read in redis_sock_read_bulk_reply() and redis_sock_read_bulk_zstr() * a timeout before the reply type byte in redis_read_reply_type() * an unknown reply type byte in redis_sock_read() and redis_sock_read_zstr() * any failed read in cluster_check_response(), which now also rejects unknown reply type bytes * a mismatched reply in cluster_send_direct(), and a mismatched reply with an unread payload in cluster_send_slot() Fixes #2960
A bulk length that doesn't parse or is out of range, or a bulk body that doesn't end in \r\n, means we no longer know where the next reply starts. Throwing or returning NULL with the socket still open lets the next command read the rest of this reply as its own. Disconnect in these cases as well: * an invalid bulk length in redis_sock_read_bulk_reply(), redis_sock_read_bulk_zstr() and redis_read_variant_bulk() * a bulk body not followed by \r\n in redis_sock_read_bulk_reply() and redis_sock_read_bulk_zstr() * a `$` length that doesn't parse or is out of range in redis_sock_read() and redis_sock_read_zstr() * a length that doesn't parse or is out of range in redis_read_reply_type() Thanks to cyppe for finding the invalid bulk length and missing \r\n checks in redis_sock_read_bulk_reply().
Previously we could leak our running transaction data if we disconnected during a transaction. Also don't accept partial cluster transaction replies. Signed-off-by: michael-grunder <michael.grunder@gmail.com>
Open
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.
This is just #2961 that has been rebased to fix merge conflicts.
Fixes #2960