fix redis: type-check pub/sub reply elements before typed access - #1345
Open
netliomax25-code wants to merge 1 commit into
Open
fix redis: type-check pub/sub reply elements before typed access#1345netliomax25-code wants to merge 1 commit into
netliomax25-code wants to merge 1 commit into
Conversation
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.
Repro: on a Redis pub/sub connection, a compromised or MITM'd server answers a subscribe/message push with an array of the expected length whose channel/count/payload element has an unexpected type, for example
["message", 42, "x"]or["subscribe", "chan", "not-an-int"].Cause:
OnSubscribeImplandSentinel::OnPsubscribeReplyinredis/src/storages/redis/impl/sentinel.cppvalidate the array length and element[0](the opcode string), then read the remaining elements withReplyData::GetString()/GetInt(). Those accessors onlyUASSERTthe type, which is a no-op underNDEBUG, and then dereference the pointer returned bystd::get_if, which is null on a type mismatch. So a mismatched-type element becomes a null-pointer dereference in release builds. #1284 added the array-length guard toOnPsubscribeReplyand #1288 fixed the separate geo parser, but the element-type gap in the pub/sub dispatch was left open.Fix: check
IsString()/IsInt()on each indexed element before the typed access in both handlers (this coversOnSubscribeReply,OnSsubscribeReplyandOnPsubscribeReply), and skip the reply otherwise. Addedsentinel_test.cppregressions feeding each mismatched-type shape; they crash on the unpatched tree under theaddr;ubsanitizer build and pass after.