diff options
author | bapt <bapt@FreeBSD.org> | 2014-10-28 16:27:29 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2014-10-28 16:27:29 +0000 |
commit | ed7e3cf94c1fe310d8ff21e987eb013fca0c2deb (patch) | |
tree | e55a4b8026f5857e61c94009c393edc95b3323b2 /lib/libutil/gr_util.c | |
parent | d92ea3ad36ae792dc6c88baf61cb3ba1c04fac58 (diff) | |
download | FreeBSD-src-ed7e3cf94c1fe310d8ff21e987eb013fca0c2deb.zip FreeBSD-src-ed7e3cf94c1fe310d8ff21e987eb013fca0c2deb.tar.gz |
Fix renaming a group via the gr_copy function
Add a regression test to pw(8) because the bug was discovered via using:
pw groupmod
PR: 187189
Reported by: mcdouga9@egr.msu.edu
Tested by: mcdouga9@egr.msu.edu
Patch by: Marc de la Gueronniere
Diffstat (limited to 'lib/libutil/gr_util.c')
-rw-r--r-- | lib/libutil/gr_util.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 6f74507..465efd9 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -170,14 +170,21 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr) size_t len; int eof, readlen; - sgr = gr; + if (old_gr == NULL && gr == NULL) + return(-1); + + sgr = old_gr; + /* deleting a group */ if (gr == NULL) { line = NULL; - if (old_gr == NULL) + } else { + if ((line = gr_make(gr)) == NULL) return (-1); - sgr = old_gr; - } else if ((line = gr_make(gr)) == NULL) - return (-1); + } + + /* adding a group */ + if (sgr == NULL) + sgr = gr; eof = 0; len = 0; |