Skip to content

Refactoring mb_str(r)(i)pos out of bound checks/errors #5109

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

Closed
wants to merge 1 commit into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jan 23, 2020

This is in part splitting #4971 where these changes were combined into.

@nikic
Copy link
Member

nikic commented Jan 24, 2020

There are some conditions where this will miss out of bounds offsets, for example if haystack is shorter than needle, which the mbfl code short-circuits.

@nikic
Copy link
Member

nikic commented Jan 24, 2020

I've now updated mbfl_strpos() to always detect offset error conditions. Can you please rebase?

@Girgias Girgias force-pushed the mbstring-pos-func-oob branch from 459ec62 to 5251ae5 Compare January 24, 2020 11:24
@@ -2084,13 +2084,13 @@ static void handle_strpos_error(size_t error) {
case MBFL_ERROR_NOT_FOUND:
break;
case MBFL_ERROR_ENCODING:
php_error_docref(NULL, E_WARNING, "Unknown encoding or conversion error");
zend_value_error("Unknown encoding or conversion error");
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave this one as a warning. This error doesn't actually occur (as far as I know), but if it did, it would be due to invalid encoding in the input string, which shouldn't throw. You can change the error message to just "Conversion error" to make that clear. (Unknown encodings are caught separately.)

@php-pulls php-pulls closed this in 986da2a Jan 24, 2020
@Girgias Girgias deleted the mbstring-pos-func-oob branch January 24, 2020 23:03
@nikic
Copy link
Member

nikic commented Jan 24, 2020

Side note, mb_strrchr still rejects empty needles.

@Girgias
Copy link
Member Author

Girgias commented Jan 24, 2020

Side note, mb_strrchr still rejects empty needles.

I'll have a look at it, must have glossed over during the (lengthy) other PR :D

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