]> granicus.if.org Git - p11-kit/commitdiff
Fix trust command segfaults in expand_homedir() when no matching password record...
authorRobert Milasan <rmilasan@suse.com>
Thu, 30 Jul 2015 09:27:13 +0000 (11:27 +0200)
committerStef Walter <stefw@redhat.com>
Fri, 31 Jul 2015 10:13:42 +0000 (12:13 +0200)
Hello, it looks like under some conditions, command trust segfaults in
expand_homedir() due to no matching password record was found:

Signed-off-by: Robert Milasan <rmilasan@suse.com>
Signed-off-by: Stef Walter <stefw@redhat.com>
 * Updated path so message is printed and errno is not overwritten

https://bugs.freedesktop.org/show_bug.cgi?id=91506

common/path.c

index 3c714d54a98ecabb9837544e2981143421eba694..34c00cba8e5846acf14c5373ed9ff4a02e904a3f 100644 (file)
@@ -133,18 +133,18 @@ expand_homedir (const char *remainder)
 #ifdef OS_UNIX
                char buf[1024];
                struct passwd pws;
-               struct passwd *pwd;
-               int error = 0;
+               struct passwd *pwd = NULL;
+               int error;
                int ret;
 
+               errno = 0;
                ret = getpwuid_r (getuid (), &pws, buf, sizeof (buf), &pwd);
-               if (ret == 0 && !pwd) {
-                       ret = -1;
-                       errno = ESRCH;
-               }
-               if (ret < 0) {
-                       error = errno;
-                       p11_message_err (errno, "couldn't lookup home directory for user %d", getuid ());
+               if (pwd == NULL) {
+                       if (ret == 0)
+                               error = ESRCH;
+                       else
+                               error = errno;
+                       p11_message_err (error, "couldn't lookup home directory for user %d", getuid ());
                        errno = error;
                        return NULL;
                }