-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix a NULL pointer dereference bug lead by php_pcre_replace_impl() #8271
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
Thanks for the new PR! This is definitely an issue that needs to be fixed in PHP-8.0 and up; I'm not quite sure about what should happen in case Anyhow, a test case matching the PR as is (without the fix, this reproduces the segfault):
|
If this segfaulted before I suppose we can add an exception? As this seems to be some sort of bug |
Yes, I think the edge-case of a failing preg_replace() has not been properly handled so far. |
php_pcre_replace_impl() will return NULL on failure. However in the function zim_RegexIterator_accept(), the return value of php_pcre_replace_impl() is directly used without any check, which could lead to NULL pointer dereference. Fix this by adding a NULL check.
8f46842
to
60bf71d
Compare
… SPL RegexIterator() The regex is precompiled during the constructions of the object at line 1424 in spl_iterators.c Moreover, the warnings emitted by pcre_get_compiled_regex_cache() get promoted to InvalidArgumentExceptions. php_pcre_replace_impl() will only return NULL in case of an internal PCRE error, something which should not happen. Closes phpGH-8271
php_pcre_replace_impl() will return NULL on failure. However, in the implementation of RegexIterator::accept() the return value of php_pcre_replace_impl() is directly used without any check, which leads to a NULL pointer dereference. Fix this by adding a NULL check, and returning false in that case. Closes phpGH-8271 Signed-off-by: George Peter Banyard <[email protected]>
php_pcre_replace_impl() will return NULL on failure. However, in the implementation of RegexIterator::accept() the return value of php_pcre_replace_impl() is directly used without any check, which leads to a NULL pointer dereference. Fix this by adding a NULL check, and returning false in that case. Closes phpGH-8271 Signed-off-by: George Peter Banyard <[email protected]>
php_pcre_replace_impl() will return NULL on failure. However, in the implementation of RegexIterator::accept() the return value of php_pcre_replace_impl() is directly used without any check, which leads to a NULL pointer dereference. Fix this by adding a NULL check, and returning false in that case. Closes phpGH-8271 Signed-off-by: George Peter Banyard <[email protected]>
php_pcre_replace_impl() will return NULL on failure. However, in the implementation of RegexIterator::accept() the return value of php_pcre_replace_impl() is directly used without any check, which leads to a NULL pointer dereference. Fix this by adding a NULL check, and returning false in that case. Closes phpGH-8271 Signed-off-by: George Peter Banyard <[email protected]>
php_pcre_replace_impl() will return NULL on failure. However, in the implementation of RegexIterator::accept() the return value of php_pcre_replace_impl() is directly used without any check, which leads to a NULL pointer dereference. Fix this by adding a NULL check, and returning false in that case. Closes phpGH-8271 Signed-off-by: George Peter Banyard <[email protected]>
This fix is incomplete as it leaks memory, but fortunately this was already fixed by b3a56bd (including a test) |
php_pcre_replace_impl() will return NULL on failure. However in the function
zim_RegexIterator_accept(), the return value of php_pcre_replace_impl()
is directly used without any check, which could lead to NULL
pointer dereference.
Fix this by adding a NULL check.
This bug is found by a static analyzer, so it is hard to reproduce it.