Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick: ICU-21449 Infinite loop can occur with locale IDs containing RES_PATH_SEPARATOR #66

Merged
merged 1 commit into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions icu/icu4c/source/common/uresbund.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,8 @@ ures_getByKeyWithFallback(const UResourceBundle *resB,
} else {
break;
}
} else if (res == RES_BOGUS) {
break;
}
} while(*myPath); /* Continue until the whole path is consumed */
}
Expand Down
16 changes: 14 additions & 2 deletions icu/icu4c/source/test/cintltst/cloctst.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void addLocaleTest(TestNode** root)
TESTCASE(TestBug20370);
TESTCASE(TestBug20321UnicodeLocaleKey);
TESTCASE(TestUsingDefaultWarning);
TESTCASE(TestBug21449InfiniteLoop);
}


Expand Down Expand Up @@ -6980,11 +6981,12 @@ static void TestUsingDefaultWarning() {
log_err("ERROR: in uloc_getDisplayKeywordValue %s %s return len:%d %s with status %d %s\n",
keyword_value, keyword, length, errorOutputBuff, status, myErrorName(status));
}
}
}

// Test case for ICU-20575
// This test checks if the environment variable LANG is set,
// and if so ensures that both C and C.UTF-8 cause ICU's default locale to be en_US_POSIX.
static void TestCDefaultLocale(){
static void TestCDefaultLocale() {
const char *defaultLocale = uloc_getDefault();
char *env_var = getenv("LANG");
if (env_var == NULL) {
Expand All @@ -6995,3 +6997,13 @@ static void TestCDefaultLocale(){
log_err("The default locale for LANG=%s should be en_US_POSIX, not %s\n", env_var, defaultLocale);
}
}

// Test case for ICU-21449
static void TestBug21449InfiniteLoop() {
UErrorCode status = U_ZERO_ERROR;
const char* invalidLocaleId = RES_PATH_SEPARATOR_S;

// The issue causes an infinite loop to occur when looking up a non-existent resource for the invalid locale ID,
// so the test is considered passed if the call to the API below returns anything at all.
uloc_getDisplayLanguage(invalidLocaleId, invalidLocaleId, NULL, 0, &status);
}
2 changes: 1 addition & 1 deletion icu/icu4c/source/test/cintltst/cloctst.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static void TestToUnicodeLocaleType(void);
static void TestToLegacyType(void);
static void TestBug20149(void);
static void TestCDefaultLocale(void);

static void TestBug21449InfiniteLoop(void);

/**
* U_USING_DEFAULT_WARNING
Expand Down