Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wayland: Check selection devices before using them #101779

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Wayland: Check selection devices before using them
Looks like we never actually stopped the code from using bad pointers.
I even forgot the check in the primary selection code 🤦
Riteo committed Jan 20, 2025
commit bed2a1927fbbc444f57f7cbb1298504ce7edc6ca
12 changes: 9 additions & 3 deletions platform/linuxbsd/wayland/wayland_thread.cpp
Original file line number Diff line number Diff line change
@@ -4111,6 +4111,7 @@ void WaylandThread::selection_set_text(const String &p_text) {

if (registry.wl_data_device_manager == nullptr) {
DEBUG_LOG_WAYLAND_THREAD("Couldn't set selection, wl_data_device_manager global not available.");
return;
}

if (ss == nullptr) {
@@ -4238,17 +4239,22 @@ void WaylandThread::primary_set_text(const String &p_text) {
return;
}

if (ss->wp_primary_selection_device == nullptr) {
DEBUG_LOG_WAYLAND_THREAD("Couldn't set primary selection, seat doesn't have wp_primary_selection_device.");
return;
}

ss->primary_data = p_text.to_utf8_buffer();

if (ss->wp_primary_selection_source == nullptr) {
ss->wp_primary_selection_source = zwp_primary_selection_device_manager_v1_create_source(registry.wp_primary_selection_device_manager);
zwp_primary_selection_source_v1_add_listener(ss->wp_primary_selection_source, &wp_primary_selection_source_listener, ss);
zwp_primary_selection_source_v1_offer(ss->wp_primary_selection_source, "text/plain;charset=utf-8");
zwp_primary_selection_source_v1_offer(ss->wp_primary_selection_source, "text/plain");
}

// TODO: Implement a good way of getting the latest serial from the user.
zwp_primary_selection_device_v1_set_selection(ss->wp_primary_selection_device, ss->wp_primary_selection_source, MAX(ss->pointer_data.button_serial, ss->last_key_pressed_serial));
// TODO: Implement a good way of getting the latest serial from the user.
zwp_primary_selection_device_v1_set_selection(ss->wp_primary_selection_device, ss->wp_primary_selection_source, MAX(ss->pointer_data.button_serial, ss->last_key_pressed_serial));
}

// Wait for the message to get to the server before continuing, otherwise the
// clipboard update might come with a delay.