From: Yu Watanabe Date: Tue, 20 Dec 2022 13:42:20 +0000 (+0900) Subject: locale: do not use alloca() for strings which can be potentially arbitrary X-Git-Tag: v253-rc1~29^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f4514e84a309e8ac0cdfd1c2852faf063cd0162;p=thirdparty%2Fsystemd.git locale: do not use alloca() for strings which can be potentially arbitrary --- diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c index 726d41e3995..03ea98d5219 100644 --- a/src/locale/localed-util.c +++ b/src/locale/localed-util.c @@ -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;