Date: Tue, 28 Oct 2014 15:46:23 +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: r273787 - in head/usr.sbin/pw: . tests Message-ID: <201410281546.s9SFkNZD022931@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Tue Oct 28 15:46:22 2014 New Revision: 273787 URL: https://svnweb.freebsd.org/changeset/base/273787 Log: Ensure pw userdel -u <invalid> do not try to remove root Check the uid passed is actually a number as early as possible MFC after: 1 week Modified: head/usr.sbin/pw/pw_user.c head/usr.sbin/pw/tests/pw_delete.sh Modified: head/usr.sbin/pw/pw_user.c ============================================================================== --- head/usr.sbin/pw/pw_user.c Tue Oct 28 15:33:15 2014 (r273786) +++ head/usr.sbin/pw/pw_user.c Tue Oct 28 15:46:22 2014 (r273787) @@ -321,6 +321,9 @@ pw_user(struct userconf * cnf, int mode, (a_uid = a_name)->ch = 'u'; a_name = NULL; } + } else { + if (strspn(a_uid->val, "0123456789") != strlen(a_uid->val)) + errx(EX_USAGE, "-u expects a number"); } /* Modified: head/usr.sbin/pw/tests/pw_delete.sh ============================================================================== --- head/usr.sbin/pw/tests/pw_delete.sh Tue Oct 28 15:33:15 2014 (r273786) +++ head/usr.sbin/pw/tests/pw_delete.sh Tue Oct 28 15:46:22 2014 (r273787) @@ -30,7 +30,18 @@ group_do_not_delete_wheel_if_group_unkow atf_check -s exit:0 -o inline:"wheel:*:0:root\n" -x pw -V ${HOME} groupshow wheel } +atf_test_case user_do_not_try_to_delete_root_if_user_unkown +user_do_not_try_to_delete_root_if_user_unkown_head() { + atf_set "descr" "Make sure not to try to remove root if deleteing an unknown user" +} + +user_do_not_try_to_delete_root_if_user_unkown_body() { + populate_etc_skel + atf_check -e inline:"pw: -u expects a number\n" -s exit:64 -x pw -V ${HOME} userdel -u plop +} + atf_init_test_cases() { atf_add_test_case rmuser_seperate_group atf_add_test_case group_do_not_delete_wheel_if_group_unkown + atf_add_test_case user_do_not_try_to_delete_root_if_user_unkown }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410281546.s9SFkNZD022931>