From 3aceadf235d1420058cb78dc73a9be288be40a6b Mon Sep 17 00:00:00 2001
From: Luca Boccassi <luca.boccassi@gmail.com>
Date: Mon, 20 Oct 2025 02:24:29 +0100
Subject: [PATCH] PolkitSubject: avoid g_dbus warning

'invocation' can be NULL, and glib doesn't like it:

 g_dbus_method_invocation_get_message: assertion 'G_IS_DBUS_METHOD_INVOCATION (invocation)' failed
 g_dbus_message_get_unix_fd_list: assertion 'G_IS_DBUS_MESSAGE (message)' failed
---
 src/polkit/polkitsubject.c | 46 ++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/src/polkit/polkitsubject.c b/src/polkit/polkitsubject.c
index 07f87d06..4f723155 100644
--- a/src/polkit/polkitsubject.c
+++ b/src/polkit/polkitsubject.c
@@ -432,28 +432,30 @@ polkit_subject_new_for_gvariant_invocation (GVariant              *variant,
           uid = -1;
         }
 
-      fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation));
-      if (fd_list)
-        {
-          v = lookup_asv (details_gvariant, "pidfd", G_VARIANT_TYPE_HANDLE, NULL);
-          if (v != NULL)
-            {
-              if (uid == -1)
-                {
-                  g_set_error (error,
-                               POLKIT_ERROR,
-                               POLKIT_ERROR_FAILED,
-                               "Error parsing unix-process subject: 'pidfd' specified withtout 'uid'");
-                  goto out;
-                }
-
-              index = g_variant_get_handle (v);
-              pidfd = g_unix_fd_list_get (fd_list, index, NULL);
-              g_variant_unref (v);
-
-              ret = polkit_unix_process_new_pidfd (pidfd, uid, NULL);
-            }
-        }
+      if (invocation) {
+        fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation));
+        if (fd_list)
+          {
+            v = lookup_asv (details_gvariant, "pidfd", G_VARIANT_TYPE_HANDLE, NULL);
+            if (v != NULL)
+              {
+                if (uid == -1)
+                  {
+                    g_set_error (error,
+                                POLKIT_ERROR,
+                                POLKIT_ERROR_FAILED,
+                                "Error parsing unix-process subject: 'pidfd' specified withtout 'uid'");
+                    goto out;
+                  }
+
+                index = g_variant_get_handle (v);
+                pidfd = g_unix_fd_list_get (fd_list, index, NULL);
+                g_variant_unref (v);
+
+                ret = polkit_unix_process_new_pidfd (pidfd, uid, NULL);
+              }
+          }
+      }
 
       if (!ret)
         {
