ICULocaleBackend: Validate that the created locale really exists.

Locale::createCanonical will happily accept all kinds of strings
that don't actually indicate valid locales, but down the line
ICU will behave strangely or even crash with these in certain methods.

So, use getISO3Language(), which will return nothing if the language
is unknown to ICU, to validate that the locale exists, or bail if
it doesn't.

Fixes #19576.
This commit is contained in:
Augustin Cavalier
2025-05-29 17:10:47 -04:00
parent 6ef33c54e0
commit 183a60a7bc
@@ -88,6 +88,13 @@ ICULocaleBackend::SetLocale(int category, const char* posixLocaleName)
return _SetPosixLocale(category);
Locale locale = Locale::createCanonical(posixLocaleName);
// Locale::create doesn't check validity, so make sure the locale
// has a real ISO-3166 language code to validate that it actually exists.
const char* iso3166 = locale.getISO3Language();
if (iso3166 == NULL || iso3166[0] == '\0')
return NULL;
switch (category) {
case LC_ALL:
if (fCollateData.SetTo(locale, posixLocaleName) != B_OK