PolicyKit: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Wed Feb 23 12:11:38 PST 2011


 src/polkitbackend/polkitbackendinteractiveauthority.c |   22 +++++++++------
 src/programs/pkcheck.c                                |   26 ++++++++++--------
 2 files changed, 29 insertions(+), 19 deletions(-)

New commits:
commit b031cf007ff8ac08055a737d69e5d83a13e8ef7c
Author: David Zeuthen <davidz at redhat.com>
Date:   Wed Feb 23 15:11:07 2011 -0500

    Be a bit more careful parsing the command-line
    
    In particular, avoid crashing for Zombies
    
    Signed-off-by: David Zeuthen <davidz at redhat.com>

diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c
index 4293fdd..84f47f1 100644
--- a/src/polkitbackend/polkitbackendinteractiveauthority.c
+++ b/src/polkitbackend/polkitbackendinteractiveauthority.c
@@ -485,7 +485,7 @@ _polkit_subject_get_cmdline (PolkitSubject *subject)
     }
   else
     {
-      g_warning ("Unknown subject type passed to guess_program_name()");
+      g_warning ("Unknown subject type passed to _polkit_subject_get_cmdline()");
       goto out;
     }
 
@@ -505,15 +505,21 @@ _polkit_subject_get_cmdline (PolkitSubject *subject)
       goto out;
     }
 
-  /* The kernel uses '\0' to separate arguments - replace those with a space. */
-  for (n = 0; n < contents_len - 1; n++)
+  if (contents == NULL || contents_len == 0)
     {
-      if (contents[n] == '\0')
-        contents[n] = ' ';
+      goto out;
+    }
+  else
+    {
+      /* The kernel uses '\0' to separate arguments - replace those with a space. */
+      for (n = 0; n < contents_len - 1; n++)
+        {
+          if (contents[n] == '\0')
+            contents[n] = ' ';
+        }
+      ret = g_strdup (contents);
+      g_strstrip (ret);
     }
-
-  ret = g_strdup (contents);
-  g_strstrip (ret);
 
  out:
   g_free (filename);
diff --git a/src/programs/pkcheck.c b/src/programs/pkcheck.c
index bbe2011..719a36c 100644
--- a/src/programs/pkcheck.c
+++ b/src/programs/pkcheck.c
@@ -145,7 +145,7 @@ _polkit_subject_get_cmdline (PolkitSubject *subject)
     }
   else
     {
-      g_warning ("Unknown subject type passed to guess_program_name()");
+      g_warning ("Unknown subject type passed to _polkit_subject_get_cmdline()");
       goto out;
     }
 
@@ -165,15 +165,21 @@ _polkit_subject_get_cmdline (PolkitSubject *subject)
       goto out;
     }
 
-  /* The kernel uses '\0' to separate arguments - replace those with a space. */
-  for (n = 0; n < contents_len - 1; n++)
+  if (contents == NULL || contents_len == 0)
     {
-      if (contents[n] == '\0')
-        contents[n] = ' ';
+      goto out;
+    }
+  else
+    {
+      /* The kernel uses '\0' to separate arguments - replace those with a space. */
+      for (n = 0; n < contents_len - 1; n++)
+        {
+          if (contents[n] == '\0')
+            contents[n] = ' ';
+        }
+      ret = g_strdup (contents);
+      g_strstrip (ret);
     }
-
-  ret = g_strdup (contents);
-  g_strstrip (ret);
 
  out:
   g_free (filename);
@@ -281,8 +287,6 @@ do_list_or_revoke_temp_authz (gboolean revoke)
           obtained_rel_str = format_reltime (obtained - now.tv_sec);
           expires_rel_str = format_reltime (expires - now.tv_sec);
 
-          /* TODO: could print cmdline of subject etc. */
-
           g_print ("authorization id: %s\n"
                    "action:           %s\n"
                    "subject:          %s (%s)\n"
@@ -291,7 +295,7 @@ do_list_or_revoke_temp_authz (gboolean revoke)
                    "\n",
                    id,
                    action_id,
-                   subject_str, subject_cmdline,
+                   subject_str, subject_cmdline != NULL ? subject_cmdline : "cannot read cmdline",
                    obtained_rel_str, obtained_str,
                    expires_rel_str, expires_str);
 


More information about the hal-commit mailing list