git: 1de93128e75a - main - pw: reject ' and ` in user/group names
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Nov 2026 14:39:15 UTC
The branch main has been updated by bofh:
URL: https://cgit.FreeBSD.org/src/commit/?id=1de93128e75a8571f0fcefc3394d2f875adf970f
commit 1de93128e75a8571f0fcefc3394d2f875adf970f
Author: Muhammad Moinur Rahman <bofh@FreeBSD.org>
AuthorDate: 2026-11-10 14:15:10 +0000
Commit: Muhammad Moinur Rahman <bofh@FreeBSD.org>
CommitDate: 2026-11-10 14:38:18 +0000
pw: reject ' and ` in user/group names
pw_checkname() already refuses $ ( ) and freinds, but backtick and
single quote slipped thru, so `pw useradd 'foo`id`'` went in just
fine. Thats command substitution in any unquoted context. Add both
to badchars, plus a test.
Reported by: Harry Sintonen (Reversec)
Sponsored by: Entersekt
MFC after: 2 weeks
Approved by: bapt
Differential Revision: https://reviews.freebsd.org/D61392
---
usr.sbin/pw/pw_user.c | 2 +-
usr.sbin/pw/tests/pw_useradd_test.sh | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
index 492c44731178..4faa06612fd5 100644
--- a/usr.sbin/pw/pw_user.c
+++ b/usr.sbin/pw/pw_user.c
@@ -629,7 +629,7 @@ pw_checkname(char *name, int gecos)
showtype = "gecos field";
} else {
/* See if the name is valid as a userid or group. */
- badchars = " ,\t:+&#%$^()!@~*?<>=|\\/\";";
+ badchars = " ,\t:+&#%$^()!@~*?<>=|\\/\";'`";
showtype = "userid/group name";
/* Userids and groups can not have a leading '-'. */
if (*ch == '-')
diff --git a/usr.sbin/pw/tests/pw_useradd_test.sh b/usr.sbin/pw/tests/pw_useradd_test.sh
index 82c8d8b8524f..1f98691611b7 100755
--- a/usr.sbin/pw/tests/pw_useradd_test.sh
+++ b/usr.sbin/pw/tests/pw_useradd_test.sh
@@ -186,6 +186,21 @@ user_add_name_with_spaces_body() {
atf_check -s exit:1 -o empty grep "^test user:.*" $HOME/master.passwd
}
+atf_test_case user_add_name_with_quotes
+user_add_name_with_quotes_body() {
+ populate_etc_skel
+ for user_name in 'test`id`' "test'user"; do
+ atf_check -s exit:65 -e match:"invalid character" \
+ ${PW} useradd "${user_name}"
+ atf_check -s exit:65 -e match:"invalid character" \
+ ${PW} useradd -n "${user_name}"
+ atf_check -s exit:65 -e match:"invalid character" \
+ ${PW} groupadd "${user_name}"
+ done
+ atf_check -s exit:1 -o empty grep "^test" $HOME/master.passwd
+ atf_check -s exit:1 -o empty grep "^test" $HOME/group
+}
+
atf_test_case user_add_name_with_spaces_and_gid_specified
user_add_name_with_spaces_and_gid_specified_body() {
populate_etc_skel
@@ -578,6 +593,7 @@ atf_init_test_cases() {
atf_add_test_case user_add_password_expiration_date_relative
atf_add_test_case user_add_name_too_long
atf_add_test_case user_add_name_with_spaces
+ atf_add_test_case user_add_name_with_quotes
atf_add_test_case user_add_name_with_spaces_and_gid_specified
atf_add_test_case user_add_expiration
atf_add_test_case user_add_invalid_user_entry