Merge branch 'PHP-7.1' into PHP-7.2

* PHP-7.1:
  Fixed #75539 and #74183 - preg_last_error not returning error code after error
This commit is contained in:
Anatol Belski 2017-11-21 20:11:21 +01:00
commit f6b0d365a7
3 changed files with 36 additions and 0 deletions

View file

@ -362,6 +362,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
#endif #endif
php_error_docref(NULL, E_WARNING, php_error_docref(NULL, E_WARNING,
p < ZSTR_VAL(regex) + ZSTR_LEN(regex) ? "Null byte in regex" : "Empty regular expression"); p < ZSTR_VAL(regex) + ZSTR_LEN(regex) ? "Null byte in regex" : "Empty regular expression");
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL; return NULL;
} }
@ -375,6 +376,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} }
#endif #endif
php_error_docref(NULL,E_WARNING, "Delimiter must not be alphanumeric or backslash"); php_error_docref(NULL,E_WARNING, "Delimiter must not be alphanumeric or backslash");
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL; return NULL;
} }
@ -425,6 +427,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} else { } else {
php_error_docref(NULL,E_WARNING, "No ending matching delimiter '%c' found", delimiter); php_error_docref(NULL,E_WARNING, "No ending matching delimiter '%c' found", delimiter);
} }
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL; return NULL;
} }
@ -473,6 +476,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} else { } else {
php_error_docref(NULL,E_WARNING, "Null byte in regex"); php_error_docref(NULL,E_WARNING, "Null byte in regex");
} }
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
efree(pattern); efree(pattern);
#if HAVE_SETLOCALE #if HAVE_SETLOCALE
if (key != regex) { if (key != regex) {
@ -503,6 +507,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} }
#endif #endif
php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %d", error, erroffset); php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %d", error, erroffset);
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
efree(pattern); efree(pattern);
if (tables) { if (tables) {
pefree((void*)tables, 1); pefree((void*)tables, 1);
@ -534,6 +539,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} }
if (error != NULL) { if (error != NULL) {
php_error_docref(NULL, E_WARNING, "Error while studying pattern"); php_error_docref(NULL, E_WARNING, "Error while studying pattern");
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
} }
} else { } else {
extra = NULL; extra = NULL;
@ -569,6 +575,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} }
#endif #endif
php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc); php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL; return NULL;
} }
@ -580,6 +587,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} }
#endif #endif
php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc); php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL; return NULL;
} }

View file

@ -0,0 +1,15 @@
--TEST--
Bug #74183 - preg_last_error not returning error code after error
--FILE--
<?php
$sRegex = "/([A-Z]|[a-z]|[0-9]| |Ñ|ñ|!|&quot;|%|&amp;|'|´|-|:|;|>|=|&lt;|@|_|,|\{|\}|`|~|á|é|í|ó|ú|Á|É|Í|Ó|Ú|ü|Ü){1,300}/";
$sTest = "Hello world";
var_dump(preg_match($sRegex, $sTest));
var_dump(preg_last_error() === \PREG_INTERNAL_ERROR);
?>
--EXPECTF--
Warning: preg_match(): Compilation failed: regular expression is too large at offset %s in %s on line %s
bool(false)
bool(true)

View file

@ -0,0 +1,13 @@
--TEST--
Bug #75539 - Recursive call errors are not reported by preg_last_error()
--FILE--
<?php
var_dump(preg_match('/((?1)?z)/', ''));
var_dump(preg_last_error() === \PREG_INTERNAL_ERROR);
?>
--EXPECTF--
Warning: preg_match(): Compilation failed: recursive call could loop indefinitely at offset %s in %s on line %s
bool(false)
bool(true)