From f024e9536279b7c47fe2b1d656a86d3b3f50b716 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 23 Oct 2018 08:01:21 -0400 Subject: [PATCH] Check that wayland-0 is a socket This is a little better than just checking that the file exists. Still does not protect against a stale socket. Closes: #2258 Closes: #2271 Approved by: matthiasclasen --- common/flatpak-run.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/flatpak-run.c b/common/flatpak-run.c index 588ab034..0abca6d8 100644 --- a/common/flatpak-run.c +++ b/common/flatpak-run.c @@ -234,6 +234,7 @@ flatpak_run_add_wayland_args (FlatpakBwrap *bwrap) g_autofree char *wayland_socket = NULL; g_autofree char *sandbox_wayland_socket = NULL; gboolean res = FALSE; + struct stat statbuf; wayland_display = g_getenv ("WAYLAND_DISPLAY"); if (!wayland_display) @@ -242,7 +243,8 @@ flatpak_run_add_wayland_args (FlatpakBwrap *bwrap) wayland_socket = g_build_filename (g_get_user_runtime_dir (), wayland_display, NULL); sandbox_wayland_socket = g_strdup_printf ("/run/user/%d/%s", getuid (), wayland_display); - if (g_file_test (wayland_socket, G_FILE_TEST_EXISTS)) + if (stat (wayland_socket, &statbuf) == 0 && + (statbuf.st_mode & S_IFMT) == S_IFSOCK) { res = TRUE; flatpak_bwrap_add_args (bwrap,