OpenFile portal: do not use O_PATH fds
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Sun, 3 Mar 2024 09:03:16 +0000 (09:03 +0000)
committerSteve Langasek <vorlon@debian.org>
Sun, 3 Mar 2024 09:03:16 +0000 (09:03 +0000)
Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=03cbcba7b2b0e42a
Last-Update: 2023-05-13

Using O_PATH requires correctly specifying whether the fd is writable or
not. Stating that the fd is writable without it actually being writable
results into rejection on xdg-desktop-portal side. Other implementations
like xdg-open or gtk have also moved away from O_PATH fds so this will
make a matching implementation and avoid possible rejections from xdp.

Gbp-Pq: Name dont_use_O_PATH.diff

src/platformsupport/services/genericunix/qgenericunixservices.cpp

index 1a3cab275d85023352089afb6e756f8a270383f3..4cb2cf7c481d9f22b676c94645bd81d797087fba 100644 (file)
@@ -203,8 +203,7 @@ static inline QDBusMessage xdgDesktopPortalOpenFile(const QUrl &url)
     // handle_token (s) -  A string that will be used as the last element of the @handle.
     // writable (b) - Whether to allow the chosen application to write to the file.
 
-#ifdef O_PATH
-    const int fd = qt_safe_open(QFile::encodeName(url.toLocalFile()), O_PATH);
+    const int fd = qt_safe_open(QFile::encodeName(url.toLocalFile()), O_RDONLY);
     if (fd != -1) {
         QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.portal.Desktop"),
                                                               QLatin1String("/org/freedesktop/portal/desktop"),
@@ -214,16 +213,13 @@ static inline QDBusMessage xdgDesktopPortalOpenFile(const QUrl &url)
         QDBusUnixFileDescriptor descriptor;
         descriptor.giveFileDescriptor(fd);
 
-        const QVariantMap options = {{QLatin1String("writable"), true}};
+        const QVariantMap options = {};
 
         // FIXME parent_window_id
         message << QString() << QVariant::fromValue(descriptor) << options;
 
         return QDBusConnection::sessionBus().call(message);
     }
-#else
-    Q_UNUSED(url)
-#endif
 
     return QDBusMessage::createError(QDBusError::InternalError, qt_error_string());
 }