Date: Tue, 28 Jul 2015 21:10:59 +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: r285985 - in head/usr.sbin/pw: . tests Message-ID: <201507282110.t6SLAx0k035167@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Tue Jul 28 21:10:58 2015 New Revision: 285985 URL: https://svnweb.freebsd.org/changeset/base/285985 Log: Check uid/gid used when creating a user/group are not larger than UID_MAX/GID_MAX PR: 173977 Reported by: nvass@gmx.com Added: head/usr.sbin/pw/tests/pw_groupadd.sh (contents, props changed) Modified: head/usr.sbin/pw/pw.c head/usr.sbin/pw/tests/Makefile head/usr.sbin/pw/tests/pw_useradd.sh Modified: head/usr.sbin/pw/pw.c ============================================================================== --- head/usr.sbin/pw/pw.c Tue Jul 28 20:52:10 2015 (r285984) +++ head/usr.sbin/pw/pw.c Tue Jul 28 21:10:58 2015 (r285985) @@ -269,7 +269,7 @@ main(int argc, char *argv[]) } if (strspn(optarg, "0123456789") != strlen(optarg)) errx(EX_USAGE, "-g expects a number"); - id = strtonum(optarg, 0, LONG_MAX, &errstr); + id = strtonum(optarg, 0, GID_MAX, &errstr); if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", optarg, errstr); @@ -281,7 +281,7 @@ main(int argc, char *argv[]) addarg(&arglist, 'u', optarg); break; } - id = strtonum(optarg, 0, LONG_MAX, &errstr); + id = strtonum(optarg, 0, UID_MAX, &errstr); if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", optarg, errstr); Modified: head/usr.sbin/pw/tests/Makefile ============================================================================== --- head/usr.sbin/pw/tests/Makefile Tue Jul 28 20:52:10 2015 (r285984) +++ head/usr.sbin/pw/tests/Makefile Tue Jul 28 21:10:58 2015 (r285985) @@ -8,6 +8,7 @@ TESTSDIR= ${TESTSBASE}/usr.sbin/pw ATF_TESTS_SH= pw_etcdir \ pw_lock \ pw_config \ + pw_groupadd \ pw_groupdel \ pw_groupmod \ pw_useradd \ Added: head/usr.sbin/pw/tests/pw_groupadd.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/pw/tests/pw_groupadd.sh Tue Jul 28 21:10:58 2015 (r285985) @@ -0,0 +1,15 @@ +# $FreeBSD$ + +# Import helper functions +. $(atf_get_srcdir)/helper_functions.shin + +atf_test_case group_add_gid_too_large +group_add_gid_too_large_body() { + populate_etc_skel + atf_check -s exit:64 -e inline:"pw: Bad id '9999999999999': too large\n" \ + ${PW} groupadd -n test1 -g 9999999999999 +} + +atf_init_test_cases() { + atf_add_test_case group_add_gid_too_large +} Modified: head/usr.sbin/pw/tests/pw_useradd.sh ============================================================================== --- head/usr.sbin/pw/tests/pw_useradd.sh Tue Jul 28 20:52:10 2015 (r285984) +++ head/usr.sbin/pw/tests/pw_useradd.sh Tue Jul 28 21:10:58 2015 (r285985) @@ -289,6 +289,13 @@ user_add_uid0_body() { -s exit:0 ${PW} usershow foo } +atf_test_case user_add_uid_too_large +user_add_uid_too_large_body() { + populate_etc_skel + atf_check -s exit:64 -e inline:"pw: Bad id '9999999999999': too large\n" \ + ${PW} useradd -n test1 -u 9999999999999 +} + atf_init_test_cases() { atf_add_test_case user_add atf_add_test_case user_add_noupdate @@ -313,4 +320,5 @@ atf_init_test_cases() { atf_add_test_case user_add_R atf_add_test_case user_add_skel atf_add_test_case user_add_uid0 + atf_add_test_case user_add_uid_too_large }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507282110.t6SLAx0k035167>