pw: fix setmode(NULL) crash when homemode is a boolean value
This commit is contained in:
+10
-4
@@ -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))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user