Fix segfault when input events arrive during initialization#190
Open
Yiin wants to merge 1 commit intoemersion:masterfrom
Open
Fix segfault when input events arrive during initialization#190Yiin wants to merge 1 commit intoemersion:masterfrom
Yiin wants to merge 1 commit intoemersion:masterfrom
Conversation
Move cursor surface creation and cursor theme loading before the second wl_display_roundtrip(), which is the first point where the compositor can dispatch pointer_enter or keyboard events to slurp via the newly-created layer surfaces. Previously, cursor_surface was created after the roundtrip, so pointer_handle_enter could call wl_surface_set_buffer_scale() or wp_cursor_shape_manager_v1_get_pointer() with a NULL surface. Similarly, keyboard_handle_key and keyboard_handle_modifiers could dereference NULL xkb_state if a keyboard event arrived before the keymap event. This race is especially pronounced on setups with many outputs (e.g. headless virtual monitors), where the roundtrip takes longer due to output enumeration, widening the window for events to arrive before initialization completes. Also add defensive NULL checks in the affected handlers as a safety net. Fixes: emersion#181
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
Fixes the segfault reported in #181 caused by pointer/keyboard events arriving before cursor surfaces and xkb state are initialized.
cursor_surfacecreation and cursor theme loading before the secondwl_display_roundtrip(), which is the first point where the compositor dispatches input events via newly-created layer surfacespointer_handle_enter,keyboard_handle_key, andkeyboard_handle_modifiersas a safety netRoot cause
During initialization, seat listeners are registered in the first roundtrip (via
handle_global→create_seat), butcursor_surfaceis only created after the second roundtrip. When the compositor sends apointer_enterevent during that second roundtrip (triggered by the layer surfaces committing),pointer_handle_enterdereferences a NULLcursor_surfaceinsidewl_surface_set_buffer_scale()orwp_cursor_shape_manager_v1_get_pointer().The same class of bug affects
keyboard_handle_keyandkeyboard_handle_modifiers, which can dereference NULLxkb_stateif a keyboard event arrives before the keymap event.Reproduction
The race is timing-dependent but becomes nearly deterministic with many outputs (e.g. 45+ headless virtual monitors on Hyprland), as the roundtrip takes longer to enumerate all outputs, widening the window for events to arrive before initialization completes. Using
wayfreeze --after-freeze-cmd "slurp ..."also exacerbates it since slurp immediately inherits pointer focus.Crash backtrace:
Fixes #181