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

ICU-21449 Infinite loop can occur with locale IDs that contain RES_PATH_SEPARATOR #1549

Merged

Conversation

jefgen
Copy link
Member

@jefgen jefgen commented Jan 28, 2021

When calling APIs like uloc_getDisplayLanguage, if the input locale ID has / (the RES_PATH_SEPARATOR value) then the resource look-up code ends up in an infinite loop.

For example, the following code will never return:

UErrorCode status = U_ZERO_ERROR;
const char* localeNameTemp = "/"; // RES_PATH_SEPARATOR
uloc_getDisplayLanguage(localeNameTemp, localeNameTemp, NULL, 0, &status);

The do {...} while loop in ures_getByKeyWithFallback calls res_findResource, but it never checks to see if the returned resource is RES_BOGUS, meaning that for some paths it will never terminate. (Thanks to am11 for doing the initial investigation into this issue.)

This PR also includes a test case for the issue. Note that there is nothing really "tested" by the test case, as the test is to simply ensure that calling the API doesn't cause a hang due to the infinite loop.

Checklist

jefgen added a commit to microsoft/icu that referenced this pull request Jan 29, 2021
@jefgen jefgen merged commit 8082d0e into unicode-org:master Jan 29, 2021
@jefgen jefgen deleted the jefgen/fix-infinite-loop-ICU-21449 branch January 29, 2021 21:10
jefgen added a commit to microsoft/icu that referenced this pull request Feb 1, 2021
…ontain RES_PATH_SEPARATOR (#66)

This change cherry-picks the upstream fix for the issue of an infinite loop when calling various APIs with locale IDs that contain `RES_PATH_SEPARATOR`.

Upstream ticket:
https://unicode-org.atlassian.net/browse/ICU-21449

Upstream PR:
unicode-org/icu#1549

Detailed Description (from the upstream PR):
When calling APIs like `uloc_getDisplayLanguage`, if the input locale ID has `/` (the `RES_PATH_SEPARATOR` value) then the resource look-up code ends up in an infinite loop.

For example, the following code will never return:

```c++
UErrorCode status = U_ZERO_ERROR;
const char* localeNameTemp = "/"; // RES_PATH_SEPARATOR
uloc_getDisplayLanguage(localeNameTemp, localeNameTemp, NULL, 0, &status);
```

The `do {...} while` loop in `ures_getByKeyWithFallback` calls `res_findResource`, but it never checks to see if the returned resource is `RES_BOGUS`, meaning that for some paths it will never terminate. (Thanks to am11 for doing the initial investigation into this issue.)

This PR also includes a test case for the issue. Note that there is nothing really "tested" by the test case, as the test is to simply ensure that calling the API doesn't cause a hang due to the infinite loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants