summaryrefslogtreecommitdiffstats
path: root/login-utils/last.c
diff options
context:
space:
mode:
authorKarel Zak2014-07-17 14:39:11 +0200
committerKarel Zak2014-07-17 14:39:11 +0200
commit2e118e709bce91b3397dafdb1e25137f33bab31f (patch)
tree31471ea813105e46f083a373d391b7577bc847f3 /login-utils/last.c
parentlibmount: add missing assert() (diff)
downloadkernel-qcow2-util-linux-2e118e709bce91b3397dafdb1e25137f33bab31f.tar.gz
kernel-qcow2-util-linux-2e118e709bce91b3397dafdb1e25137f33bab31f.tar.xz
kernel-qcow2-util-linux-2e118e709bce91b3397dafdb1e25137f33bab31f.zip
last: fix is_phantom() logic [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/last.c')
-rw-r--r--login-utils/last.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/login-utils/last.c b/login-utils/last.c
index 4c70eaaaf..f0c2b8c87 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -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);