summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2011-02-23 15:11:07 -0500
committerDavid Zeuthen <davidz@redhat.com>2011-02-23 15:11:07 -0500
commitb031cf007ff8ac08055a737d69e5d83a13e8ef7c (patch)
tree25fa2732dc40706453f9b693fd25b9aa4c6615ab
parenta0ec8e52e9e471cf2a989b26fe6a98cc15e294ad (diff)
Be a bit more careful parsing the command-line
In particular, avoid crashing for Zombies Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--src/polkitbackend/polkitbackendinteractiveauthority.c22
-rw-r--r--src/programs/pkcheck.c26
2 files changed, 29 insertions, 19 deletions
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);