From: Eric Daigle Date: Fri, 9 Feb 2024 07:09:34 +0000 (-0800) Subject: firstboot: validate keymap entry X-Git-Tag: v256-rc1~903 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=321a8c595e3470a0fe9002014656eee6a50b9553;p=thirdparty%2Fsystemd.git firstboot: validate keymap entry As described in #30940, systemd-firstboot currently does not perform any validation on keymap entry, allowing nonexistent keymaps to be written to /etc/vconsole.conf. This commit adds validation checks based on those already performed on locale entry, preventing invalid keymaps from being set. Closes #30940 m --- diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 652a6d5c89f..76af4e4ed52 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -458,6 +458,20 @@ static int process_locale(int rfd) { return 1; } +static bool keymap_exists_bool(const char *name) { + return keymap_exists(name) > 0; +} + +static typeof(&keymap_is_valid) determine_keymap_validity_func(int rfd) { + int r; + + r = dir_fd_is_root(rfd); + if (r < 0) + log_debug_errno(r, "Unable to determine if operating on host root directory, assuming we are: %m"); + + return r != 0 ? keymap_exists_bool : keymap_is_valid; +} + static int prompt_keymap(int rfd) { _cleanup_strv_free_ char **kmaps = NULL; int r; @@ -489,7 +503,7 @@ static int prompt_keymap(int rfd) { print_welcome(rfd); return prompt_loop("Please enter system keymap name or number", - kmaps, 60, keymap_is_valid, &arg_keymap); + kmaps, 60, determine_keymap_validity_func(rfd), &arg_keymap); } static int process_keymap(int rfd) { @@ -1695,6 +1709,8 @@ static int run(int argc, char *argv[]) { /* We check these conditions here instead of in parse_argv() so that we can take the root directory * into account. */ + if (arg_keymap && !determine_keymap_validity_func(rfd)(arg_keymap)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Keymap %s is not installed.", arg_keymap); if (arg_locale && !locale_is_ok(rfd, arg_locale)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Locale %s is not installed.", arg_locale); if (arg_locale_messages && !locale_is_ok(rfd, arg_locale_messages))