]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale: escape invalid keymap on logging
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 26 Jul 2025 19:04:27 +0000 (04:04 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 Aug 2025 15:25:03 +0000 (16:25 +0100)
The keymap string may come from dbus method and may contain invalid
characters.

(cherry picked from commit 0464222aed4bc025c117df9b650d62684274c6fd)

src/locale/localed-util.c

index 6413288ea3d5f85345b75cde6e035d274d771f23..7de79a1547d576a0424f910d70e1fc97761d1925 100644 (file)
@@ -10,6 +10,7 @@
 #include "env-file-label.h"
 #include "env-file.h"
 #include "env-util.h"
+#include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
@@ -257,15 +258,16 @@ static int verify_keymap(const char *keymap, int log_level, sd_bus_error *error)
         assert(keymap);
 
         r = keymap_exists(keymap); /* This also verifies that the keymap name is kosher. */
-        if (r < 0) {
-                if (error)
-                        sd_bus_error_set_errnof(error, r, "Failed to check keymap %s: %m", keymap);
-                return log_full_errno(log_level, r, "Failed to check keymap %s: %m", keymap);
-        }
-        if (r == 0) {
+        if (r <= 0) {
+                _cleanup_free_ char *escaped = cescape(keymap);
+                if (r < 0) {
+                        if (error)
+                                sd_bus_error_set_errnof(error, r, "Failed to check keymap %s: %m", strna(escaped));
+                        return log_full_errno(log_level, r, "Failed to check keymap %s: %m", strna(escaped));
+                }
                 if (error)
-                        sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "Keymap %s is not installed.", keymap);
-                return log_full_errno(log_level, SYNTHETIC_ERRNO(ENOENT), "Keymap %s is not installed.", keymap);
+                        sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "Keymap %s is not installed.", strna(escaped));
+                return log_full_errno(log_level, SYNTHETIC_ERRNO(ENOENT), "Keymap %s is not installed.", strna(escaped));
         }
 
         return 0;