]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
Close some file descriptor leaks in pw
authorAlan Somers <asomers@FreeBSD.org>
Fri, 21 Oct 2016 20:17:19 +0000 (20:17 +0000)
committerAlan Somers <asomers@FreeBSD.org>
Fri, 21 Oct 2016 20:17:19 +0000 (20:17 +0000)
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D8245

pw/grupd.c
pw/pw_nis.c
pw/pwupd.c

index 9cbe0cb0b345814ee2299abfcc50e94423352d92..38d5e5bc956ce26b01dae3e2ca470e08132d485e 100644 (file)
@@ -34,6 +34,7 @@ static const char rcsid[] =
 #include <libutil.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "pwupd.h"
 
@@ -73,8 +74,10 @@ gr_update(struct group * grp, char const * group)
        }
        if (gr_copy(pfd, tfd, gr, old_gr) == -1) {
                gr_fini();
+               close(tfd);
                err(1, "gr_copy()");
        }
+       close(tfd);
        if (gr_mkdb() == -1) {
                gr_fini();
                err(1, "gr_mkdb()");
index 6cc361b7a25c57ff27b5fe01a2edfbdc7fd646e1..35b26ea5224b55eac884a0e06cac3533f7e0e90a 100644 (file)
@@ -34,6 +34,7 @@ static const char rcsid[] =
 #include <err.h>
 #include <pwd.h>
 #include <libutil.h>
+#include <unistd.h>
 
 #include "pw.h"
 
@@ -63,8 +64,10 @@ pw_nisupdate(const char * path, struct passwd * pwd, char const * user)
        }
        if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
                pw_fini();
+               close(tfd);
                err(1, "pw_copy()");
        }
+       close(tfd);
        if (chmod(pw_tempname(), 0644) == -1)
                err(1, "chmod()");
        if (rename(pw_tempname(), path) == -1)
index ee23952e090f6f8f1d962e305fe39ad70522ce21..3bcb95f8c4651af838cb258567c1ec358ddba622 100644 (file)
@@ -111,8 +111,10 @@ pw_update(struct passwd * pwd, char const * user)
        }
        if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
                pw_fini();
+               close(tfd);
                err(1, "pw_copy()");
        }
+       close(tfd);
        /*
         * in case of deletion of a user, the whole database
         * needs to be regenerated