]> 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>
Sat, 26 Jul 2025 23:58:02 +0000 (00:58 +0100)
The keymap string may come from dbus method and may contain invalid
characters.

src/locale/localed-util.c

index 72f317f0b0c7eb86d7802072cea6973378655691..2842570ddacb289fe27844910714c1fec3c656dd 100644 (file)
@@ -9,6 +9,7 @@
 #include "copy.h"
 #include "env-file.h"
 #include "errno-util.h"
+#include "escape.h"
 #include "extract-word.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -60,15 +61,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;