Skip to content

Commit

Permalink
sealed-fd: Handle more error conditions in from_handle
Browse files Browse the repository at this point in the history
This allows passing in a GVariant and GUnixFDList directly from the DBus
APIs without having to do pre condition checking in the caller.
  • Loading branch information
swick authored and jadahl committed Nov 14, 2024
1 parent 9fc85c0 commit 41ca139
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
18 changes: 0 additions & 18 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
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

0 comments on commit 41ca139

Please sign in to comment.