From: Karel Zak Date: Mon, 30 Jan 2012 23:10:53 +0000 (+0100) Subject: chfn: fix use-after-free [coverity scan] X-Git-Tag: v2.21-rc2~68 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7871178226658350f012e2ce7e7a70bcc6821b13;p=thirdparty%2Futil-linux.git chfn: fix use-after-free [coverity scan] access FILE pointer after failed fclose() results in undefined behavior Signed-off-by: Karel Zak --- diff --git a/login-utils/setpwnam.c b/login-utils/setpwnam.c index 7593a52b8c..0e0c0478d4 100644 --- a/login-utils/setpwnam.c +++ b/login-utils/setpwnam.c @@ -76,7 +76,7 @@ int setpwnam(struct passwd *pwd) int oldumask; int namelen; int buflen = 256; - int contlen; + int contlen, rc; char *linebuf = NULL; oldumask = umask(0); /* Create with exact permissions */ @@ -159,9 +159,11 @@ int setpwnam(struct passwd *pwd) fputs(linebuf, fp); } - if (fclose(fp) < 0) - goto fail; + rc = fclose(fp); fp = NULL; + if (rc < 0) + goto fail; + close(fd); fd = -1; fclose(pwf); /* I don't think I want to know if this failed */