Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Oct 2014 14:54:05 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273782 - in head/usr.sbin/pw: . tests
Message-ID:  <201410281454.s9SEs5kb098825@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Tue Oct 28 14:54:04 2014
New Revision: 273782
URL: https://svnweb.freebsd.org/changeset/base/273782

Log:
  Do not delete the group wheel when bad argument is passed to pw groupdel -g
  
  Check that the -g argument is actually a number, if not report an error.
  This argument is converted without checking with atoi(3) later so without this
  check it converts any alpha entries into 0 meaning it deletes the group wheel
  
  Add a regression test about it
  
  PR:		90114
  Reported by:	bkoenig@cs.tu-berlin.de
  MFC after:	1 week

Modified:
  head/usr.sbin/pw/pw_group.c
  head/usr.sbin/pw/tests/pw_delete.sh

Modified: head/usr.sbin/pw/pw_group.c
==============================================================================
--- head/usr.sbin/pw/pw_group.c	Tue Oct 28 14:49:10 2014	(r273781)
+++ head/usr.sbin/pw/pw_group.c	Tue Oct 28 14:54:04 2014	(r273782)
@@ -67,6 +67,11 @@ pw_group(struct userconf * cnf, int mode
 		NULL
 	};
 
+	if (a_gid != NULL) {
+		if (strspn(a_gid->val, "0123456789") != strlen(a_gid->val))
+			errx(EX_USAGE, "-g expects a number");
+	}
+
 	if (mode == M_LOCK || mode == M_UNLOCK)
 		errx(EX_USAGE, "'lock' command is not available for groups");
 

Modified: head/usr.sbin/pw/tests/pw_delete.sh
==============================================================================
--- head/usr.sbin/pw/tests/pw_delete.sh	Tue Oct 28 14:49:10 2014	(r273781)
+++ head/usr.sbin/pw/tests/pw_delete.sh	Tue Oct 28 14:54:04 2014	(r273782)
@@ -18,7 +18,19 @@ rmuser_seperate_group_body() {
 	pw -V ${HOME} userdel test || atf_fail "delete the user"
 }
 
+atf_test_case group_do_not_delete_wheel_if_group_unkown
+group_do_not_delete_wheel_if_group_unkown_head() {
+	atf_set "descr" "Make sure we do not consider as gid 0 an unknown group"
+}
+
+group_do_not_delete_wheel_if_group_unkown_body() {
+	populate_etc_skel
+	atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x pw -V ${HOME} groupshow wheel
+	atf_check -e inline:"pw: -g expects a number\n" -s exit:64 -x pw -V ${HOME} groupdel -g I_do_not_exist
+	atf_check -s exit:0 -o "wheel:*:0:root\n" -x pw -V ${HOME} groupshow wheel
+}
 
 atf_init_test_cases() {
 	atf_add_test_case rmuser_seperate_group
+	atf_add_test_case group_do_not_delete_wheel_if_group_unkown
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410281454.s9SEs5kb098825>