From 2cedc86f21a6bdb9ad16be16a3fe9390bf2d08ce Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 29 Jun 2026 23:16:14 +0200 Subject: [PATCH] wayland: Validate the wayland socket name before using it If validation failed, we fall back to wayland-0, but we passed the unvalidated name to flatpak_run_create_wayland_security_context. --- common/flatpak-run-wayland.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/common/flatpak-run-wayland.c b/common/flatpak-run-wayland.c index c8d2b8ff9..a48c0ae74 100644 --- a/common/flatpak-run-wayland.c +++ b/common/flatpak-run-wayland.c @@ -36,8 +36,16 @@ get_wayland_display_name (void) const char *wayland_display; wayland_display = g_getenv ("WAYLAND_DISPLAY"); - if (!wayland_display) - wayland_display = "wayland-0"; + + if (wayland_display == NULL) + return "wayland-0"; + + if (!g_str_has_prefix (wayland_display, "wayland-") || + strchr (wayland_display, '/') != NULL) + { + g_debug ("Not preserving WAYLAND_DISPLAY=\"%s\"", wayland_display); + return "wayland-0"; + } return wayland_display; } @@ -313,14 +321,6 @@ flatpak_run_add_wayland_args (FlatpakBwrap *bwrap, wayland_socket = get_wayland_socket_path (wayland_display); } - if (!g_str_has_prefix (wayland_display, "wayland-") || - strchr (wayland_display, '/') != NULL) - { - g_debug ("Not preserving WAYLAND_DISPLAY=\"%s\"", wayland_display); - wayland_display = "wayland-0"; - flatpak_bwrap_set_env (bwrap, "WAYLAND_DISPLAY", wayland_display, TRUE); - } - sandbox_wayland_socket = g_strdup_printf ("/run/flatpak/%s", wayland_display); if (stat (wayland_socket, &statbuf) == 0 && @@ -333,6 +333,8 @@ flatpak_run_add_wayland_args (FlatpakBwrap *bwrap, flatpak_bwrap_add_runtime_dir_member (bwrap, wayland_display); } + flatpak_bwrap_set_env (bwrap, "WAYLAND_DISPLAY", wayland_display, TRUE); + /* If inherit-wayland-socket is not set, unset WAYLAND_SOCKET unconditionally * without checking the validity of the value of WAYLAND_SOCKET. */ if (!inherit_wayland_socket)