Skip to content

Commit

Permalink
Merge branch 'main' into only-resolved-app-id
Browse files Browse the repository at this point in the history
  • Loading branch information
grulja authored Nov 20, 2024
2 parents be7f2f4 + d89204e commit 5df4a8f
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 59 deletions.
2 changes: 1 addition & 1 deletion data/org.freedesktop.portal.GlobalShortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
* ``preferred_trigger`` (``s``)
The preferred shortcut trigger, defined as described by the
`shortcuts XDG specification <https://specifications.freedesktop.org/shortcuts-spec/shortcuts-latest.txt>`__.
`shortcuts XDG specification <https://specifications.freedesktop.org/shortcuts-spec/latest/>`__.
Optional.
Supported keys in the @options vardict include:
Expand Down
4 changes: 2 additions & 2 deletions data/org.freedesktop.portal.Notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
The following categories are standarized so far:
* ``im.message``
* ``im.received``
Intended for instant messaging apps displaying notifications for new messages.
Expand Down Expand Up @@ -331,7 +331,7 @@
Disable the speakerphone for the ongoing call.
* ``call.missed``
* ``call.unanswered``
Intended to be used by call apps when a call was missed.
Expand Down
68 changes: 46 additions & 22 deletions src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ selection_write_done (GObject *source_object,
g_autoptr(GUnixFDList) fd_list = NULL;
g_autoptr(GVariant) fd_handle = NULL;
g_autoptr(GError) error = NULL;
int fd;
int fd_id;
int out_fd_id = -1;

if (!xdp_dbus_impl_clipboard_call_selection_write_finish (
Expand All @@ -193,24 +191,36 @@ selection_write_done (GObject *source_object,

if (fd_handle)
{
fd_id = g_variant_get_handle (fd_handle);
fd = g_unix_fd_list_get (fd_list, fd_id, &error);
int fd_id = g_variant_get_handle (fd_handle);

out_fd_id = g_unix_fd_list_append (out_fd_list, fd, &error);
if (fd_id < g_unix_fd_list_get_length (fd_list))
{
g_autofd int fd = -1;

close (fd);
fd = g_unix_fd_list_get (fd_list, fd_id, &error);

if (out_fd_id == -1)
if (fd >= 0)
out_fd_id = g_unix_fd_list_append (out_fd_list, fd, &error);
}
else
{
g_dbus_method_invocation_return_error (
invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_FAILED,
"Failed to append fd: %s",
error->message);
g_set_error_literal (&error, XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Bad file descriptor index");
}
}

if (out_fd_id == -1)
{
g_dbus_method_invocation_return_error (
invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_FAILED,
"Failed to append fd: %s",
error->message);
return;
}

xdp_dbus_clipboard_complete_selection_write (
NULL,
invocation,
Expand Down Expand Up @@ -327,10 +337,7 @@ selection_read_done (GObject *source_object,
g_autoptr(GUnixFDList) fd_list = NULL;
g_autoptr(GVariant) fd_handle = NULL;
g_autoptr(GError) error = NULL;

int fd;
int fd_id;
int out_fd_id;
int out_fd_id = -1;

if (!xdp_dbus_impl_clipboard_call_selection_read_finish (
impl, &fd_handle, &fd_list, res, &error))
Expand All @@ -339,12 +346,28 @@ selection_read_done (GObject *source_object,
g_warning ("A backend call failed: %s", error->message);
}

fd_id = g_variant_get_handle (fd_handle);
fd = g_unix_fd_list_get (fd_list, fd_id, &error);

out_fd_list = g_unix_fd_list_new ();
out_fd_id = g_unix_fd_list_append (out_fd_list, fd, &error);
close (fd);

if (fd_handle)
{
int fd_id = g_variant_get_handle (fd_handle);

if (fd_id < g_unix_fd_list_get_length (fd_list))
{
g_autofd int fd = -1;

fd = g_unix_fd_list_get (fd_list, fd_id, &error);

if (fd >= 0)
out_fd_id = g_unix_fd_list_append (out_fd_list, fd, &error);
}
else
{
g_set_error_literal (&error, XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Bad file descriptor index");
}
}

if (out_fd_id == -1)
{
Expand All @@ -353,6 +376,7 @@ selection_read_done (GObject *source_object,
XDG_DESKTOP_PORTAL_ERROR_FAILED,
"Failed to append fd: %s",
error->message);
return;
}

xdp_dbus_clipboard_complete_selection_read (
Expand Down
14 changes: 12 additions & 2 deletions src/email.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,18 @@ handle_compose_email (XdpDbusEmail *object,
{
g_autofree char *path = NULL;
int fd_id;
int fd;
g_autofd int fd = -1;

g_variant_get_child (attachment_fds, i, "h", &fd_id);
if (fd_id >= g_unix_fd_list_get_length (fd_list))
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Bad file descriptor index");
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

fd = g_unix_fd_list_get (fd_list, fd_id, &error);
if (fd == -1)
{
Expand All @@ -261,7 +270,8 @@ handle_compose_email (XdpDbusEmail *object,

/* Don't leak any info about real file path existence, etc */
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Invalid attachment fd passed");
return G_DBUS_METHOD_INVOCATION_HANDLED;
}
Expand Down
22 changes: 2 additions & 20 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,6 @@ parse_serialized_icon (GVariantBuilder *builder,
if (!check_value_type (key, value, G_VARIANT_TYPE_HANDLE, error))
return FALSE;

if (in_fd_list == NULL || g_unix_fd_list_get_length (in_fd_list) == 0)
{
g_set_error_literal (error,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Invalid file descriptor: No Unix FD list given or empty");
return FALSE;
}

if (!(sealed_icon = xdp_sealed_fd_new_from_handle (value,
in_fd_list,
&local_error)))
Expand Down Expand Up @@ -783,15 +774,6 @@ parse_serialized_sound (GVariantBuilder *builder,
if (!check_value_type (key, value, G_VARIANT_TYPE_HANDLE, error))
return FALSE;

if (in_fd_list == NULL || g_unix_fd_list_get_length (in_fd_list) == 0)
{
g_set_error_literal (error,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Invalid file descriptor: No Unix FD list given or empty");
return FALSE;
}

sealed_sound = xdp_sealed_fd_new_from_handle (value,
in_fd_list,
&local_error);
Expand Down Expand Up @@ -895,11 +877,11 @@ parse_category (GVariantBuilder *builder,
{
const char *category;
const char *supported_categories[] = {
"im.message",
"im.received",
"alarm.ringing",
"call.incoming",
"call.ongoing",
"call.missed",
"call.unanswered",
"weather.warning.extreme",
"cellbroadcast.danger.extreme",
"cellbroadcast.danger.severe",
Expand Down
27 changes: 22 additions & 5 deletions src/open-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,15 @@ handle_open_in_thread_func (GTask *task,
g_auto(GVariantBuilder) opts_builder =
G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
gboolean skip_app_chooser = FALSE;
g_auto(XdpFd) fd = -1;
g_autofd int fd = -1;
gboolean writable = FALSE;
gboolean ask = FALSE;
gboolean open_dir = FALSE;
gboolean use_default_app = FALSE;
const char *reason;

REQUEST_AUTOLOCK (request);

parent_window = (const char *)g_object_get_data (G_OBJECT (request), "parent-window");
uri = g_strdup ((const char *)g_object_get_data (G_OBJECT (request), "uri"));
fd = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "fd"));
Expand All @@ -625,7 +627,7 @@ handle_open_in_thread_func (GTask *task,
open_dir = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "open-dir"));
activation_token = (const char *)g_object_get_data (G_OBJECT (request), "activation-token");

REQUEST_AUTOLOCK (request);
g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (-1));

/* Verify that either uri or fd is set, not both */
if (uri != NULL && fd != -1)
Expand Down Expand Up @@ -779,9 +781,6 @@ handle_open_in_thread_func (GTask *task,
scheme = g_strdup ("file");
uri = g_filename_to_uri (path, NULL, NULL);
g_object_set_data_full (G_OBJECT (request), "uri", g_strdup (uri), g_free);
close (fd);
fd = -1;
g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (-1));
}

g_object_set_data_full (G_OBJECT (request), "scheme", g_strdup (scheme), g_free);
Expand Down Expand Up @@ -1025,6 +1024,15 @@ handle_open_file (XdpDbusOpenURI *object,
ask = FALSE;

g_variant_get (arg_fd, "h", &fd_id);
if (fd_id >= g_unix_fd_list_get_length (fd_list))
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Bad file descriptor index");
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

fd = g_unix_fd_list_get (fd_list, fd_id, &error);
if (fd == -1)
{
Expand Down Expand Up @@ -1077,6 +1085,15 @@ handle_open_directory (XdpDbusOpenURI *object,
}

g_variant_get (arg_fd, "h", &fd_id);
if (fd_id >= g_unix_fd_list_get_length (fd_list))
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Bad file descriptor index");
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

fd = g_unix_fd_list_get (fd_list, fd_id, &error);
if (fd == -1)
{
Expand Down
12 changes: 11 additions & 1 deletion src/trash.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,22 @@ handle_trash_file (XdpDbusTrash *object,
GVariant *arg_fd)
{
Call *call = call_from_invocation (invocation);
int idx, fd;
int idx;
g_autofd int fd = -1;
guint result;

g_debug ("Handling TrashFile");

g_variant_get (arg_fd, "h", &idx);
if (idx >= g_unix_fd_list_get_length (fd_list))
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Bad file descriptor index");
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

fd = g_unix_fd_list_get (fd_list, idx, NULL);

result = trash_file (call->app_info, call->sender, fd);
Expand Down
15 changes: 12 additions & 3 deletions src/wallpaper.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ handle_set_wallpaper_in_thread_func (GTask *task,
g_autoptr(XdpDbusImplRequest) impl_request = NULL;
GVariant *options;
gboolean show_preview = FALSE;
int fd;
g_autofd int fd = -1;
Permission permission;

REQUEST_AUTOLOCK (request);
Expand All @@ -145,6 +145,8 @@ handle_set_wallpaper_in_thread_func (GTask *task,
fd = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (request), "fd"));
options = ((GVariant *)g_object_get_data (G_OBJECT (request), "options"));

g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (-1));

if (uri != NULL && fd != -1)
{
g_warning ("Rejecting invalid set-wallpaper request (both URI and fd are set)");
Expand Down Expand Up @@ -267,8 +269,6 @@ handle_set_wallpaper_in_thread_func (GTask *task,

uri = g_filename_to_uri (path, NULL, NULL);
g_object_set_data_full (G_OBJECT (request), "uri", g_strdup (uri), g_free);
close (fd);
g_object_set_data (G_OBJECT (request), "fd", GINT_TO_POINTER (-1));
}

impl_request = xdp_dbus_impl_request_proxy_new_sync (g_dbus_proxy_get_connection (G_DBUS_PROXY (impl)),
Expand Down Expand Up @@ -347,6 +347,15 @@ handle_set_wallpaper_file (XdpDbusWallpaper *object,
g_debug ("Handle SetWallpaperFile");

g_variant_get (arg_fd, "h", &fd_id);
if (fd_id >= g_unix_fd_list_get_length (fd_list))
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR,
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Bad file descriptor index");
return G_DBUS_METHOD_INVOCATION_HANDLED;
}

fd = g_unix_fd_list_get (fd_list, fd_id, &error);
if (fd == -1)
{
Expand Down
15 changes: 13 additions & 2 deletions src/xdp-sealed-fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,19 @@ xdp_sealed_fd_new_from_handle (GVariant *handle,
g_autofd int fd = -1;
int fd_id;

g_return_val_if_fail (g_variant_is_of_type (handle, G_VARIANT_TYPE_HANDLE), NULL);
g_return_val_if_fail (G_IS_UNIX_FD_LIST (fd_list), NULL);
if (!g_variant_is_of_type (handle, G_VARIANT_TYPE_HANDLE))
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
"GVariant is not a file descriptor handle");
return NULL;
}

if (!fd_list)
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
"Invalid file descriptor: index not found (empty list)");
return NULL;
}

fd_id = g_variant_get_handle (handle);
if (fd_id >= g_unix_fd_list_get_length (fd_list))
Expand Down
2 changes: 1 addition & 1 deletion tests/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ test_notification_category (void)

notification_s = "{ 'title': <'test notification 5'>, "
" 'body': <'test notification body 5'>, "
" 'category': <'im.message'>"
" 'category': <'im.received'>"
"}";

run_notification_test ("test5", notification_s, NULL, FALSE);
Expand Down

0 comments on commit 5df4a8f

Please sign in to comment.