]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chfn: fix use-after-free [coverity scan]
authorKarel Zak <kzak@redhat.com>
Mon, 30 Jan 2012 23:10:53 +0000 (00:10 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 30 Jan 2012 23:10:53 +0000 (00:10 +0100)
access FILE pointer after failed fclose() results in undefined behavior

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/setpwnam.c

index 7593a52b8c950f819307ac35a656447b3fb5a8b1..0e0c0478d4ecb97742c4625543cc44a43122885a 100644 (file)
@@ -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 */