From fd30f06df47c141b1a78074d04867d0d46247da4 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Sun, 13 Sep 2026 12:33:57 -0400 Subject: [PATCH] dbus: Use the minimum privileges when opening an fd for the OpenURI portal Open files and directories as read-only, as the fd is only used as proof of access by the portal, and a mismatch between fd write permissions and the portal write parameter will cause the fd to be rejected. (cherry picked from commit fb8cdf0aa8c176c4935c5c007f66e83739f1c4c1) --- src/core/linux/SDL_dbus.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/linux/SDL_dbus.c b/src/core/linux/SDL_dbus.c index cd7f77a100..2d3ae34b0b 100644 --- a/src/core/linux/SDL_dbus.c +++ b/src/core/linux/SDL_dbus.c @@ -23,6 +23,7 @@ #include "../../stdlib/SDL_vacopy.h" #include +#include #include #ifdef SDL_USE_LIBDBUS @@ -510,7 +511,19 @@ bool SDL_DBus_OpenURI(const char *uri, const char *window_id, const char *activa } uri = decoded_path; } - fd = open(uri, O_RDWR | O_CLOEXEC); + + struct stat st; + if (stat(uri, &st) == 0) { + /* Open files and directories as read-only, as the fd is only used as proof + * of access by the portal, and a mismatch between fd write permissions and + * the portal write parameter will cause the fd to be rejected. + */ + int oflags = O_RDONLY | O_CLOEXEC; + if (S_ISDIR(st.st_mode)) { + oflags |= O_DIRECTORY; + } + fd = open(uri, oflags); + } SDL_free(decoded_path); if (fd >= 0) { msg = dbus.message_new_method_call(bus_name, path, interface, "OpenFile");