Skip to content

fix redis: type-check pub/sub reply elements before typed access - #1345

Open
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:redis-pubsub-reply-type-check
Open

fix redis: type-check pub/sub reply elements before typed access#1345
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:redis-pubsub-reply-type-check

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor

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: OnSubscribeImpl and Sentinel::OnPsubscribeReply in redis/src/storages/redis/impl/sentinel.cpp validate the array length and element [0] (the opcode string), then read the remaining elements with ReplyData::GetString()/GetInt(). Those accessors only UASSERT the type, which is a no-op under NDEBUG, and then dereference the pointer returned by std::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 to OnPsubscribeReply and #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 covers OnSubscribeReply, OnSsubscribeReply and OnPsubscribeReply), and skip the reply otherwise. Added sentinel_test.cpp regressions feeding each mismatched-type shape; they crash on the unpatched tree under the addr;ub sanitizer build and pass after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant