Commit 048bc4d
Bounds-check EventHandlerBase::is_ready() against the wait set (#2376)
is_ready() indexed wait_set.events with wait_set_event_index_, which is only
assigned once the handler is added to that wait set via add_to_wait_set(). If
is_ready() runs first (e.g. a publisher/subscription event thread racing node
setup), the index is uninitialized or refers to a different wait set, so the
access reads out of bounds and can segfault (observed with ASan during lifecycle
configure).
Initialize wait_set_event_index_ and make is_ready() return false when the index
is not within the wait set's events instead of dereferencing it. Initializing
alone is not sufficient (index 0 may still not be this handler's slot), so the
bounds check is the actual guard.
Adds a regression test that calls is_ready() on a handler that was never added to
a wait set.
Refs #2376
Co-authored-by: Mike Wake <michael.wake@aosgrp.com.au>
Generated-by: Claude Opus 4.8 (Anthropic)
Signed-off-by: Pavel Guzenfeld <pavelguzenfeld@gmail.com>
Signed-off-by: Mike Wake <michael.wake@aosgrp.com.au>1 parent 7321b44 commit 048bc4d
3 files changed
Lines changed: 33 additions & 1 deletion
File tree
- rclcpp
- include/rclcpp
- src/rclcpp
- test/rclcpp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
250 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
251 | 254 | | |
252 | 255 | | |
253 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
72 | 79 | | |
73 | 80 | | |
74 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
341 | 363 | | |
342 | 364 | | |
343 | 365 | | |
| |||
0 commit comments