Fix use-after-free in SendGoal/SendRequest awaiters when cancelled before response#47
Merged
Merged
Conversation
If the awaiting coroutine is cancelled between async_send_goal() / async_send_request() and arrival of the server response, the response callback registered on the rclcpp(_action)::Client held a reference capture to the awaiter (`[this, h]`). On cancel the awaiter and its coroutine frame are destroyed; when the late response eventually arrives the callback dereferences freed memory, producing intermittent SIGSEGVs observed in sr01 test_cancel runs. Hold awaiter mutable state (done, cancelled, response/result) through a `std::shared_ptr<State>` and capture that shared_ptr by value in both the response callback and the cancel action. The callback now survives awaiter destruction and bails out on `state->done` (set by the cancel path) before touching the dangling coroutine handle. Adds test_send_goal_cancel, which reliably trips the UAF under ASan on an unfixed build and passes cleanly with the fix.
84adab0 to
72a94dd
Compare
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.
No description provided.