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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user