From bed2a1927fbbc444f57f7cbb1298504ce7edc6ca Mon Sep 17 00:00:00 2001 From: Riteo Siuga Date: Sat, 18 Jan 2025 23:46:03 +0100 Subject: [PATCH] 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 :facepalm: --- platform/linuxbsd/wayland/wayland_thread.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/platform/linuxbsd/wayland/wayland_thread.cpp b/platform/linuxbsd/wayland/wayland_thread.cpp index c6efeac9698..5ba412a6f26 100644 --- a/platform/linuxbsd/wayland/wayland_thread.cpp +++ b/platform/linuxbsd/wayland/wayland_thread.cpp @@ -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,6 +4239,11 @@ 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) { @@ -4245,10 +4251,10 @@ void WaylandThread::primary_set_text(const String &p_text) { 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.