Skip to content

Fix use-after-free in SendGoal/SendRequest awaiters when cancelled before response#47

Merged
otamachan merged 1 commit into
mainfrom
nishino/fix-send-goal-awaiter-uaf
Apr 24, 2026
Merged

Fix use-after-free in SendGoal/SendRequest awaiters when cancelled before response#47
otamachan merged 1 commit into
mainfrom
nishino/fix-send-goal-awaiter-uaf

Conversation

@otamachan

Copy link
Copy Markdown
Owner

No description provided.

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.
@otamachan otamachan force-pushed the nishino/fix-send-goal-awaiter-uaf branch from 84adab0 to 72a94dd Compare April 24, 2026 09:27
@otamachan otamachan merged commit 158ebe2 into main Apr 24, 2026
4 checks passed
@otamachan otamachan deleted the nishino/fix-send-goal-awaiter-uaf branch April 24, 2026 10:46
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