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-20065 Prevent crash on Collator::makeInstance fail when optimized… #54

Merged
merged 2 commits into from
Aug 13, 2018
Merged

Conversation

pedberg-icu
Copy link
Contributor

In Collator::createInstance, before the call to setAttributesFromKeywords, Collator* Coll will be NULL if U_FAILURE(status). In that case (FAILURE status), setAttributesFromKeywords returns immediately and does not use the dereferenced value *coll. However, the fact that Coll is dereferenced allows C++ compilers to optimize out the NULL check in the subsequent delete. In that case a failure in makeInstance due to a bad key-value such as "collation=private-kana" will cause the "delete Coll" to crash. So we add a seemingly-redundant check for U_FAILURE(status), and return NULL if TRUE, before the call to setAttributesFromKeywords.

Checklist
  • Issue filed at https://unicode-org.atlassian.net : ICU-20065
  • Update PR title to include Issue number
  • Issue accepted
  • Tests included
  • Documentation is changed or added - no doc updates needed, but comments in code explain what is going on.

@CLAassistant
Copy link

CLAassistant commented Aug 13, 2018

CLA assistant check
All committers have signed the CLA.

jefgen
jefgen previously approved these changes Aug 13, 2018
Copy link
Member

@jefgen jefgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks Peter!

@@ -448,6 +448,13 @@ Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale,
#endif
{
coll = makeInstance(desiredLocale, status);
// Either returns NULL with U_FAILURE(status), or non-NULL with U_SUCCESS(status)
}
// The use of *coll in setAttributesFromKeywords can cause causes the NULL check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: "can cause causes" -- the wording feels a bit odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I changed how I wanted to say this midstream and forgot to delete the old wording. Fixed with another commit.

@pedberg-icu pedberg-icu merged commit 2ab00ac into unicode-org:master Aug 13, 2018
@pedberg-icu pedberg-icu deleted the 20065 branch August 13, 2018 22:36
sffc pushed a commit to sffc/icu that referenced this pull request Sep 26, 2018
ICU-20065 Prevent crash on Collator::makeInstance fail when optimized…
sffc pushed a commit to sffc/icu that referenced this pull request Sep 26, 2018
ICU-20065 Prevent crash on Collator::makeInstance fail when optimized…
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
ICU-20065 Prevent crash on Collator::makeInstance fail when optimized…
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
ICU-20065 Prevent crash on Collator::makeInstance fail when optimized…
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
ICU-20065 Prevent crash on Collator::makeInstance fail when optimized…
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
ICU-20065 Prevent crash on Collator::makeInstance fail when optimized…
hugovdm added a commit to hugovdm/icu that referenced this pull request Aug 11, 2020
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.

4 participants