Fix use two-iterator erase-remove in multiplexer::cancel to avoid UB#428
Open
L0rentz wants to merge 1 commit into
Open
Fix use two-iterator erase-remove in multiplexer::cancel to avoid UB#428L0rentz wants to merge 1 commit into
L0rentz wants to merge 1 commit into
Conversation
|
An automated preview of the documentation is available at https://428.redis.prtest3.cppalliance.org/libs/redis/doc/html/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-06-17 06:08:24 UTC |
Collaborator
|
Thanks. I think we can merge this once CI passes. I'll try to add a regression test later. |
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.
Summary
Fix an incorrect erase-remove use in
multiplexer::cancel.The current code calls the single-iterator overload of
deque::eraseon the result ofstd::remove:If
ptris not present inreqs_,std::removereturnsend(), making thiserase(end()), which is undefined behavior.This can happen when a request is cancelled after it has already been removed from the queue, for example during connection teardown or reconnect handling.
The fix is to use the normal two-iterator erase-remove form:
This also matches the two-iterator
erase(first, last)form used by the other queue-trimming functions in this file (cancel_waiting,cancel_on_conn_lost,release_push_requests).Testing
Observed with
-D_GLIBCXX_DEBUG, where the invaliderase(end())path aborts with a past-the-end iterator error.