From: Karel Zak Date: Thu, 17 Jul 2014 12:39:11 +0000 (+0200) Subject: last: fix is_phantom() logic [coverity scan] X-Git-Tag: v2.25~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e118e709bce91b3397dafdb1e25137f33bab31f;p=thirdparty%2Futil-linux.git last: fix is_phantom() logic [coverity scan] Signed-off-by: Karel Zak --- 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);