From 2e118e709bce91b3397dafdb1e25137f33bab31f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 17 Jul 2014 14:39:11 +0200 Subject: [PATCH] last: fix is_phantom() logic [coverity scan] Signed-off-by: Karel Zak --- login-utils/last.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/login-utils/last.c b/login-utils/last.c index 4c70eaaafa..f0c2b8c872 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); -- 2.47.3