-
-
Notifications
You must be signed in to change notification settings - Fork 842
ICU-23155 Fix buffer overflow in SSearchTest::offsetTest() #3546
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
base: main
Are you sure you want to change the base?
Conversation
https://unicode-org.atlassian.net/browse/ICU-23155 Use std::string instead. Root cause analysis: In printOffsets, while the pointer `s` is advanced, the remaining size `n` remains unchanged to be a constant 4096, and snprintf falsely thinks the buffer has 4096 bytes left.
|
Hooray! The files in the branch are the same across the force-push. 😃 ~ Your Friendly Jira-GitHub PR Checker Bot |
|
@markusicu can you help review this test change? |
| } | ||
|
|
||
| static char *printOffsets(char *buffer, size_t n, OrderList &list) | ||
| static char* printOffsets(std::string &buffer, OrderList &list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would all become considerably simpler if the caller wasn't required to pass in any buffer at all and the function simply returned an std::string object by value. That's what any normal C++ code would do nowadays.
| int32_t size = list.size(); | ||
| char *s = buffer; | ||
| buffer.clear(); | ||
| buffer.reserve(size * 10 + 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this some kind of performance optimization, to avoid having to dynamically resize the buffer? If so, I suggest removing it, this is test code, the possible performance gain is irrelevant compared to having a few extra lines of code to maintain.
https://unicode-org.atlassian.net/browse/ICU-23155
Use std::string instead.
Root cause analysis:
In printOffsets, while the pointer
sis advanced, the remaining sizenremains unchanged to be a constant 4096, and snprintf falsely thinks the buffer has 4096 bytes left.Checklist