Commit 2a91f171 authored by David Zeuthen's avatar David Zeuthen

Properly handle return value from getpwnam_r()

Pointed out by Kay Sievers - thanks!
Signed-off-by: default avatarDavid Zeuthen <davidz@redhat.com>
parent 3b7dfe47
...@@ -214,6 +214,7 @@ main (int argc, char *argv[]) ...@@ -214,6 +214,7 @@ main (int argc, char *argv[])
{ {
guint n; guint n;
guint ret; guint ret;
gint rc;
gboolean opt_show_help; gboolean opt_show_help;
gboolean opt_show_version; gboolean opt_show_version;
PolkitAuthority *authority; PolkitAuthority *authority;
...@@ -384,10 +385,18 @@ main (int argc, char *argv[]) ...@@ -384,10 +385,18 @@ main (int argc, char *argv[])
goto out; goto out;
} }
/* Look up information about the user we care about */ /* Look up information about the user we care about - yes, the return
if (getpwnam_r (opt_user, &pwstruct, pwbuf, sizeof pwbuf, &pw) != 0) * value of this function is a bit funky
*/
rc = getpwnam_r (opt_user, &pwstruct, pwbuf, sizeof pwbuf, &pw);
if (rc == 0 && pw == NULL)
{
g_printerr ("User `%s' does not exist.\n", opt_user);
goto out;
}
else if (pw == NULL)
{ {
g_printerr ("Error getting information for user %s: %s\n", opt_user, g_strerror (errno)); g_printerr ("Error getting information for user `%s': %s\n", opt_user, g_strerror (rc));
goto out; goto out;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment