-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-16189: underflow on preg_match/preg_match_all start_offset. #16191
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
Conversation
ext/pcre/php_pcre.c
Outdated
if (start_offset == LONG_MIN) { | ||
zend_argument_value_error(5, "must be greater than " ZEND_LONG_FMT, LONG_MIN); | ||
RETURN_THROWS(); | ||
} |
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.
if (start_offset == LONG_MIN) { | |
zend_argument_value_error(5, "must be greater than " ZEND_LONG_FMT, LONG_MIN); | |
RETURN_THROWS(); | |
} | |
if (start_offset == LONG_MIN) { | |
start_offset == LONG_MIN + 1; | |
} |
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.
not sure we should hide the issue
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.
I belive we should, user should be able to pass ZEND_LONG_MIN
.
ext/pcre/php_pcre.c
Outdated
@@ -1135,6 +1135,11 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * | |||
RETURN_FALSE; | |||
} | |||
|
|||
if (start_offset == LONG_MIN) { |
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 it possible that LONG_MIN
is smaller than the minimum value of zend_off_t
on some platforms?
For 8.4 and master we could update the start_offset
parameter of php_pcre_match_impl()
to ssize_t
since it's casted to size_t
after negation, and use SSIZE_MIN
here.
For stable branches we could use ZEND_LONG_MIN
as zend_long
is always the same as zend_off_t
.
if (start_offset == ZEND_LONG_MIN) { | ||
zend_argument_value_error(5, "must be greater than " ZEND_LONG_FMT, ZEND_LONG_MIN); | ||
RETURN_THROWS(); | ||
} |
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.
Surely it should also be checked that it is not larger than ZEND_LONG_MAX ?
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.
How long can be larger than ZEND_LONG_MAX?
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.
@mvorisek is right on this, start_offset is a zend_long.
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.
LGTM!
No description provided.