]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale-util: Restrict valid locales
authorAdrian Vovk <adrianvovk@gmail.com>
Sun, 4 Feb 2024 17:18:08 +0000 (12:18 -0500)
committerAdrian Vovk <adrianvovk@gmail.com>
Tue, 13 Feb 2024 22:31:36 +0000 (17:31 -0500)
This further restricts the charset of locales to better reflect what
locales actually look like.

This allows us to safely join locale names using the `:` character, for
instance, which cannot appear in a locale name and is used by the
`$LANGUAGE` env var

src/basic/locale-util.c

index 9e70c3f01fb2990adc5f72128d4f92f9aa166a2f..e6da5dbc631d07eb753c5a7a7f423b1ba0e53d68 100644 (file)
@@ -260,7 +260,10 @@ bool locale_is_valid(const char *name) {
         if (!filename_is_valid(name))
                 return false;
 
-        if (!string_is_safe(name))
+        /* Locales look like: ll_CC.ENC@variant, where ll and CC are alphabetic, ENC is alphanumeric with
+         * dashes, and variant seems to be alphabetic.
+         * See: https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html */
+        if (!in_charset(name, ALPHANUMERICAL "_.-@"))
                 return false;
 
         return true;