-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix out-of bounds access #2382
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
Fix out-of bounds access #2382
Conversation
Test case: strnatcmp_ex(L"333", 3, L"333 ", 4, true) The reason this bug didn't come up earlier is probably because most input strings are null-terminated.
Should be covered by a test |
The "isspace" calls also miss bounds-checks, except for input that is null-terminated.
also the following "isdigit" should check for bounds. |
Also the behavior of "compare_left" is strange. The result is unlike what other "natural" string comparison functions would do,e .g.. CompareString + SORT_DIGITSASNUMBERS on Windows, or CFStringCompare + kCFCompareNumerically on macOS. Maybe the whole function should be rewritten? |
could you please add a test to trigger this bug? (as long as the problem could be seen via valgrind) |
It's probably not possible to test this from PHP, as this assumes non-terminated strings. I've ran into this issue recently when fixing issues with parse_url on non-terminated strings. Maybe we can introduce something like ext/test where we can include tests like this? |
@nikic that sounds reasonable to me, may be useful for many other things also ... |
Test extension has been added in #2414, it is now possible to write a test for this. Example of how an unterminated string test looks like: https://github.com/nikic/php-src/blob/e81452b5c39a950272d3606a07c3591f70414960/ext/standard/tests/url/parse_url_unterminated.phpt |
@Zenju please update this PR with a test ... |
Regression test:
|
Test case: strnatcmp_ex(L"333", 3, L"333 ", 4, true)
The reason this bug didn't come up earlier is probably because most input strings are null-terminated.