git: fe1e912d5a39 - main - pw: fix setmode(NULL) crash when homemode is a boolean value
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 05 Jun 2026 06:02:38 UTC
The branch main has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=fe1e912d5a394565e9adfbc443555ae0b3f087e5
commit fe1e912d5a394565e9adfbc443555ae0b3f087e5
Author: Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2026-06-04 22:13:52 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2026-06-05 06:01:50 +0000
pw: fix setmode(NULL) crash when homemode is a boolean value
---
usr.sbin/pw/pw_conf.c | 14 ++++++++++----
usr.sbin/pw/tests/pw_config_test.sh | 12 ++++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/usr.sbin/pw/pw_conf.c b/usr.sbin/pw/pw_conf.c
index 21c4824ead93..7e8fdd375395 100644
--- a/usr.sbin/pw/pw_conf.c
+++ b/usr.sbin/pw/pw_conf.c
@@ -298,10 +298,16 @@ read_userconfig(char const * file)
? "/home" : newstr(q);
break;
case _UC_HOMEMODE:
- modeset = setmode(q);
- config.homemode = (q == NULL || !boolean_val(q, 1))
- ? _DEF_DIRMODE : getmode(modeset, _DEF_DIRMODE);
- free(modeset);
+ if (q == NULL || !boolean_val(q, 1)) {
+ config.homemode = _DEF_DIRMODE;
+ } else {
+ modeset = setmode(q);
+ if (modeset == NULL)
+ errx(1, "Invalid mode: '%s'", q);
+ config.homemode = getmode(modeset,
+ _DEF_DIRMODE);
+ free(modeset);
+ }
break;
case _UC_SHELLPATH:
config.shelldir = (q == NULL || !boolean_val(q, 1))
diff --git a/usr.sbin/pw/tests/pw_config_test.sh b/usr.sbin/pw/tests/pw_config_test.sh
index e9209190dc5e..4087653fd4bb 100755
--- a/usr.sbin/pw/tests/pw_config_test.sh
+++ b/usr.sbin/pw/tests/pw_config_test.sh
@@ -19,7 +19,19 @@ modify_config_uid_gid_boundaries_body() {
cat ${HOME}/foo.conf
}
+atf_test_case homemode_boolean_no_crash
+homemode_boolean_no_crash_head() {
+ atf_set "descr" "Verify that homemode = yes in config gives a clean error"
+}
+homemode_boolean_no_crash_body() {
+ echo 'homemode = yes' > ${HOME}/bad.conf
+ populate_etc_skel
+ atf_check -s exit:1 -e inline:"pw: Invalid mode: 'yes'\n" \
+ ${PW} useradd -D -C ${HOME}/bad.conf
+}
+
atf_init_test_cases() {
atf_add_test_case generate_config
atf_add_test_case modify_config_uid_gid_boundaries
+ atf_add_test_case homemode_boolean_no_crash
}