diff options
author | Karel Zak <kzak@redhat.com> | 2012-01-31 00:10:53 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2012-01-31 00:10:53 +0100 |
commit | 7871178226658350f012e2ce7e7a70bcc6821b13 (patch) | |
tree | 5e1a6a7b30c6c1595cb648dfd0a07e770e32d1fd | |
parent | 0113a20e933c4ecf903db6fe8e442f6581d8bdba (diff) | |
download | util-linux-7871178226658350f012e2ce7e7a70bcc6821b13.tar.gz |
chfn: fix use-after-free [coverity scan]
access FILE pointer after failed fclose() results in undefined behavior
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | login-utils/setpwnam.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/login-utils/setpwnam.c b/login-utils/setpwnam.c index 7593a52b..0e0c0478 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 */ |