]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale: do not use alloca() for strings which can be potentially arbitrary
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Dec 2022 13:42:20 +0000 (22:42 +0900)
committerLuca Boccassi <bluca@debian.org>
Mon, 23 Jan 2023 11:29:11 +0000 (11:29 +0000)
src/locale/localed-util.c

index 726d41e3995ea1e79c77f9f78eab17a0a006cdf4..03ea98d5219480c4d69deee462eebc13c27f901c 100644 (file)
@@ -563,17 +563,24 @@ int find_legacy_keymap(Context *c, char **ret) {
                 }
         }
 
-        if (best_matching < 10 && c->x11_layout) {
+        if (best_matching < 10 && !isempty(c->x11_layout)) {
+                _cleanup_free_ char *l = NULL, *v = NULL, *converted = NULL;
+
                 /* The best match is only the first part of the X11
                  * keymap. Check if we have a converted map which
                  * matches just the first layout.
                  */
-                char *l, *v = NULL, *converted;
 
-                l = strndupa_safe(c->x11_layout, strcspn(c->x11_layout, ","));
-                if (c->x11_variant)
-                        v = strndupa_safe(c->x11_variant,
-                                          strcspn(c->x11_variant, ","));
+                l = strndup(c->x11_layout, strcspn(c->x11_layout, ","));
+                if (!l)
+                        return -ENOMEM;
+
+                if (!isempty(c->x11_variant)) {
+                        v = strndup(c->x11_variant, strcspn(c->x11_variant, ","));
+                        if (!v)
+                                return -ENOMEM;
+                }
+
                 r = find_converted_keymap(l, v, &converted);
                 if (r < 0)
                         return r;