From 7d0a1c5c58fdcd731b3b53a8729b7ef0e2b5b8bc Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 7 Jan 2020 11:10:05 +0000 Subject: [PATCH] tests: Fix callback arguments in fake-document-portal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Fixes: #1983 --- gio/tests/fake-document-portal.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gio/tests/fake-document-portal.c b/gio/tests/fake-document-portal.c index bb2b4e95d..c9bb7950b 100644 --- a/gio/tests/fake-document-portal.c +++ b/gio/tests/fake-document-portal.c @@ -20,6 +20,10 @@ /* A stub implementation of xdg-document-portal covering enough to * support g_document_portal_add_documents */ +#include +#include +#include + #include "fake-document-portal-generated.h" static gboolean @@ -36,18 +40,22 @@ on_handle_get_mount_point (FakeDocuments *object, static gboolean on_handle_add_full (FakeDocuments *object, GDBusMethodInvocation *invocation, - GVariant *o_path_fds, + GUnixFDList *o_path_fds, guint flags, const gchar *app_id, - const gchar *permissions, + const gchar * const *permissions, gpointer user_data) { const gchar **doc_ids = NULL; GVariant *extra_out = NULL; gsize length, i; - length = g_variant_get_size (o_path_fds); - doc_ids = g_new0 (const gchar *, length); + if (o_path_fds != NULL) + 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++) { doc_ids[i] = "document-id";