From 07c4accca887ca0d3ea817b59e03725a56964661 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 21 Oct 2016 20:17:19 +0000 Subject: [PATCH] Close some file descriptor leaks in pw MFC after: 4 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D8245 --- usr.sbin/pw/grupd.c | 3 +++ usr.sbin/pw/pw_nis.c | 3 +++ usr.sbin/pw/pwupd.c | 2 ++ 3 files changed, 8 insertions(+) diff --git a/usr.sbin/pw/grupd.c b/usr.sbin/pw/grupd.c index 9cbe0cb0b345..38d5e5bc956c 100644 --- a/usr.sbin/pw/grupd.c +++ b/usr.sbin/pw/grupd.c @@ -34,6 +34,7 @@ static const char rcsid[] = #include #include #include +#include #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()"); diff --git a/usr.sbin/pw/pw_nis.c b/usr.sbin/pw/pw_nis.c index 6cc361b7a25c..35b26ea5224b 100644 --- a/usr.sbin/pw/pw_nis.c +++ b/usr.sbin/pw/pw_nis.c @@ -34,6 +34,7 @@ static const char rcsid[] = #include #include #include +#include #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) diff --git a/usr.sbin/pw/pwupd.c b/usr.sbin/pw/pwupd.c index ee23952e090f..3bcb95f8c465 100644 --- a/usr.sbin/pw/pwupd.c +++ b/usr.sbin/pw/pwupd.c @@ -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