Skip to content

ICU-23413 Fix null pointer dereference in RuleBasedNumberFormat::getRuleSetDisplayName#4006

Open
UnLucky252 wants to merge 1 commit into
unicode-org:mainfrom
UnLucky252:fix-ICU-23413-rbnf
Open

ICU-23413 Fix null pointer dereference in RuleBasedNumberFormat::getRuleSetDisplayName#4006
UnLucky252 wants to merge 1 commit into
unicode-org:mainfrom
UnLucky252:fix-ICU-23413-rbnf

Conversation

@UnLucky252

Copy link
Copy Markdown

Linked Jira issue

ICU-23413

Summary

In RuleBasedNumberFormat::getRuleSetDisplayName (icu4c/source/i18n/rbnf.cpp),
the result of localeName.getBuffer(len + 1) was indexed via
localeStr[len] = 0 in the following loop without a NULL check.

Cause

UnicodeString::getBuffer(int32_t) returns NULL on allocation failure
(or when the string is bogus); the indexed write is then undefined
behavior.

Fix

Return a bogus UnicodeString when getBuffer returns NULL.

Testing

Existing tests pass (no behavior change on the success path). No new
test added — the OOM path requires allocator injection that is not
part of the standard test harness.

Notes

Found by static analysis (Svace, ISP RAS).

Checklist

  • Required: Issue filed: ICU-23413
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable
  • Approver: Feel free to merge on my behalf

…uleSetDisplayName

localeName.getBuffer(len + 1) can return NULL on allocation failure
(or when the string is bogus). The result was indexed via
localeStr[len] = 0 in the following loop without a NULL check, which
is undefined behavior on OOM.

Return a bogus UnicodeString when getBuffer returns NULL.

Found by static analysis (Svace, ISP RAS).
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.

1 participant