Repository navigation
libobs: release a hotkey's bindings before the hotkey is freed (#3044) - #3045
Conversation
unregister_hotkey() freed the hotkey, then called remove_bindings(), whose obs_hotkey_binding_release() reads binding->hotkey->pressed through obs_hotkey_binding_count_fields(): a use-after-free on every unregister of a hotkey that has a pressed binding. test_hotkey_binding_press_steps/remove_bindings_releases is the RED: it fails on the macOS Tier 2 lane with 1 != 2 at test_hotkey_binding_press_steps.c:317, because the allocator there reuses the freed block and the release call is lost. Linux only hides it. Moving remove_bindings() above the frees releases the bindings while the hotkey is alive. Fixes #3044
|
Coordinator: this fixes master (macOS Tier 2 has been red since #3032 merged). Please mark it ready once the PR CI and the Tier 2 runs you need are green, and I will queue it right away. If you can, also show the ASan job catching the use-after-free on the pre-fix tree on Linux, since Linux currently passes only by luck. |
|
GREEN on the lane that produced the RED: dispatched PR CI on this branch: Fast Gate, Tier 2 Linux (build, tests ON/OFF, both serial shards), Format, CI Mode, Event Data, Validate Data pass; the Sanitizers Ready for the merge queue. |
zackees
left a comment
There was a problem hiding this comment.
Coordinator review: LGTM. This is the master fix. Moving remove_bindings(id) ahead of the frees is the minimal change: the release now reads a live hotkey's pressed count. Build 🧱 / Rust Tier 2 (macos-26) passes on this head, which is the RED lane from #3032. No C test or public header is touched. The one red check, CEF Chromium Support 🌐, is the known Windows-pin lag (#2417), not this diff. It is already set to merge when green.
macOS evidence: this PR is the fix for the master-side redThe
That is master reading the hotkey's pressed count after the hotkey is freed: Local Linux lanes are green here; macOS confirmation will come from the merge queue. |
|
ASan job landed, as promised.
So the fix is green on both the lane that produced the RED (macOS Tier 2, run 41039924489) and on ASan. PR CI is green with this job, auto-merge is on, and the branch is the only thing left in the queue. |
… (obs-rust#3057) PR obs-rust#3045 fixed a use-after-free in unregister_hotkey(): remove_bindings() now runs before the hotkey is freed, so a held binding's release callback is delivered instead of being lost. That is a user-visible fix for an upstream latent bug, so it belongs in docs/features.md under "Fixed upstream bugs / Stability"; obs-rust#3045 landed without the line.
Fixes #3044
unregister_hotkey()freed the hotkey and then calledremove_bindings().remove_bindings()releases every pressed binding it removes, andobs_hotkey_binding_release()readsbinding->hotkey->pressed(throughobs_hotkey_binding_count_fields()): the hotkey had already beenbfreed. The release callback then depends on whatever the allocator left there — the "last release calls" event is lost when the block is reused, and under ASan it is a use-after-free.RED
Already in the tree, on the macOS Tier 2 lane, from the characterization test that landed in #3032:
https://github.com/obs-rust/obs-studio/actions/runs/41036571990/job/123998913951
Line 317 is
assert_int_equal(num_calls, 2)afterobs_hotkey_unregister(id); the presses before it passed (hotkey->pressed == 2). So the release call is what went missing — on Linux the same assertion passes only because the freed block still holds2.No test is edited here: the failing test is the RED, the one-line reorder is the GREEN.
GREEN
76438593e— moveremove_bindings(id)above the threebfrees inunregister_hotkey(), with a comment saying why the order matters. Bindings are now released while their hotkey is alive, so the count is real and the callback fires as the test pins.Validation
Build 🧱 / Rust Tier 2 (macos-26)), the lane that produced the RED, runs on this PR; the assertion at line 317 is the check.test/cmockain this PR's scope I will paste the before/after there.docs/features.mdline: the observable behaviour (a released hotkey reports its last release) is the contract the new test already documents, and this restores it rather than adding a feature.