]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vconsole: reject empty layout during keymap conversion with error
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 10 Jul 2026 16:59:24 +0000 (17:59 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 15 Jul 2026 20:13:24 +0000 (21:13 +0100)
A leading-dash console keymap or leading-comma X11 layout can produce an
empty layout while converting between the two formats. find_converted_keymap()
then asserts on it, allowing malformed input to abort callers such as localed.

Return EINVAL for an empty derived layout instead.

Follow-up for 6d0f5027364518ef17ef91b61dad945e1c4fd0f5

src/locale/test-localed-util.c
src/shared/vconsole-util.c

index 8e41406298a06c93925e63227642fe822ae0abe3..9bcc80200969f350942ecc86fc99b507d4bfaf8e 100644 (file)
@@ -79,6 +79,11 @@ TEST(vconsole_convert_to_x11) {
         ASSERT_OK(vconsole_convert_to_x11(&vc, x11_context_verify, &xc));
         ASSERT_TRUE(x11_context_isempty(&xc));
 
+        log_info("/* test leading-dash keymap */");
+        ASSERT_OK(free_and_strdup(&vc.keymap, "-foo"));
+        ASSERT_ERROR(vconsole_convert_to_x11(&vc, x11_context_verify, &xc), EINVAL);
+        ASSERT_TRUE(x11_context_isempty(&xc));
+
         log_info("/* test without variant, new mapping (es:) */");
         ASSERT_OK(free_and_strdup(&vc.keymap, "es"));
         ASSERT_OK(vconsole_convert_to_x11(&vc, x11_context_verify, &xc));
@@ -148,6 +153,11 @@ TEST(x11_convert_to_vconsole) {
         ASSERT_OK(x11_convert_to_vconsole(&xc, &vc));
         ASSERT_TRUE(vc_context_isempty(&vc));
 
+        log_info("/* test leading-comma layout */");
+        ASSERT_OK(free_and_strdup(&xc.layout, ",us"));
+        ASSERT_ERROR(x11_convert_to_vconsole(&xc, &vc), EINVAL);
+        ASSERT_TRUE(vc_context_isempty(&vc));
+
         log_info("/* test without variant, new mapping (es:) */");
         ASSERT_OK(free_and_strdup(&xc.layout, "es"));
         ASSERT_OK(x11_convert_to_vconsole(&xc, &vc));
index 9e56ce823df42cc369da4286ece9a042f034f339..a780b273aab2bcf344b152367a035107e285a610 100644 (file)
@@ -352,9 +352,11 @@ int find_converted_keymap(const X11Context *xc, char **ret) {
         int r;
 
         assert(xc);
-        assert(!isempty(xc->layout));
         assert(ret);
 
+        if (isempty(xc->layout))
+                return -EINVAL;
+
         if (xc->variant)
                 n = strjoin(xc->layout, "-", xc->variant);
         else