tests: Fix callback arguments in fake-document-portal

They didn’t match the prototype generated by `gdbus-codegen`, which
meant that the FD list was being iterated incorrectly. Secondly, the
document ID list returned by the method was not NULL terminated, which
could lead to reading off the end of the list.

Somehow, neither of these bugs caused problems on Linux, but they did
cause problems on FreeBSD.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1983
This commit is contained in:
Philip Withnall 2020-01-07 11:10:05 +00:00
parent 85c19a7977
commit 7d0a1c5c58

View File

@ -20,6 +20,10 @@
/* A stub implementation of xdg-document-portal covering enough to /* A stub implementation of xdg-document-portal covering enough to
* support g_document_portal_add_documents */ * support g_document_portal_add_documents */
#include <glib.h>
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
#include "fake-document-portal-generated.h" #include "fake-document-portal-generated.h"
static gboolean static gboolean
@ -36,18 +40,22 @@ on_handle_get_mount_point (FakeDocuments *object,
static gboolean static gboolean
on_handle_add_full (FakeDocuments *object, on_handle_add_full (FakeDocuments *object,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
GVariant *o_path_fds, GUnixFDList *o_path_fds,
guint flags, guint flags,
const gchar *app_id, const gchar *app_id,
const gchar *permissions, const gchar * const *permissions,
gpointer user_data) gpointer user_data)
{ {
const gchar **doc_ids = NULL; const gchar **doc_ids = NULL;
GVariant *extra_out = NULL; GVariant *extra_out = NULL;
gsize length, i; gsize length, i;
length = g_variant_get_size (o_path_fds); if (o_path_fds != NULL)
doc_ids = g_new0 (const gchar *, length); length = g_unix_fd_list_get_length (o_path_fds);
else
length = 0;
doc_ids = g_new0 (const gchar *, length + 1 /* NULL terminator */);
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
doc_ids[i] = "document-id"; doc_ids[i] = "document-id";