summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2017-08-26 00:35:49 +0000
committeremaste <emaste@FreeBSD.org>2017-08-26 00:35:49 +0000
commit75c367731c924e73c5bd87ab4b974c42917990d8 (patch)
treec155ccb6cff3bb47007d219f5a2099be694f617c /usr.sbin
parent29950b4d42af3ed4288220d2f8e1ab1fc578a423 (diff)
downloadFreeBSD-src-75c367731c924e73c5bd87ab4b974c42917990d8.zip
FreeBSD-src-75c367731c924e73c5bd87ab4b974c42917990d8.tar.gz
MFC r322677: pw usermod: Properly deal with empty secondary group lists (-G '')
PR: 221417 Relnotes: Yes
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pw/pw_user.c4
-rwxr-xr-xusr.sbin/pw/tests/pw_usermod_test.sh3
2 files changed, 5 insertions, 2 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
index 76849ba..a71be12 100644
--- a/usr.sbin/pw/pw_user.c
+++ b/usr.sbin/pw/pw_user.c
@@ -1087,10 +1087,10 @@ split_groups(StringList **groups, char *groupsstr)
char *p;
char tok[] = ", \t";
+ if (*groups == NULL)
+ *groups = sl_init();
for (p = strtok(groupsstr, tok); p != NULL; p = strtok(NULL, tok)) {
grp = group_from_name_or_id(p);
- if (*groups == NULL)
- *groups = sl_init();
sl_add(*groups, newstr(grp->gr_name));
}
}
diff --git a/usr.sbin/pw/tests/pw_usermod_test.sh b/usr.sbin/pw/tests/pw_usermod_test.sh
index 6a13130..cf3622f 100755
--- a/usr.sbin/pw/tests/pw_usermod_test.sh
+++ b/usr.sbin/pw/tests/pw_usermod_test.sh
@@ -128,6 +128,9 @@ user_mod_nogroups_body() {
atf_check -s exit:0 ${PW} usermod foo -G test3,test4
atf_check -s exit:0 -o inline:"test3\ntest4\n" \
awk -F\: '$4 == "foo" { print $1 }' ${HOME}/group
+ atf_check -s exit:0 ${PW} usermod foo -G ""
+ atf_check -s exit:0 -o empty \
+ awk -F\: '$4 == "foo" { print $1 }' ${HOME}/group
}
atf_test_case user_mod_rename
OpenPOWER on IntegriCloud