]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: fix is_phantom() logic [coverity scan]
authorKarel Zak <kzak@redhat.com>
Thu, 17 Jul 2014 12:39:11 +0000 (14:39 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 17 Jul 2014 12:39:11 +0000 (14:39 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/last.c

index 4c70eaaafaebd24b52112e547fb69fd5d9164501..f0c2b8c8723fb53272b3a385cff4707f8c026935 100644 (file)
@@ -582,7 +582,7 @@ static int is_phantom(const struct last_control *ctl, struct utmp *ut)
 {
        struct passwd *pw;
        char path[32];
-       FILE *f;
+       FILE *f = NULL;
        unsigned int loginuid;
        int ret = 0;
 
@@ -592,10 +592,9 @@ static int is_phantom(const struct last_control *ctl, struct utmp *ut)
        if (!pw)
                return 1;
        sprintf(path, "/proc/%u/loginuid", ut->ut_pid);
-       if (access(path, R_OK) == 0 && !(f = fopen(path, "r")))
+       if (access(path, R_OK) != 0 || !(f = fopen(path, "r")))
                return 1;
-       else
-               return ret;
+
        if (fscanf(f, "%u", &loginuid) != 1)
                ret = 1;
        fclose(f);