com php-src: Fixed #75539 and #74183 - preg_last_error no t returning error code after error: ext/pcre/php _pcre.c ext/pcre/tests/bug74183.phpt ext/pc
re/tests/bug75539.phpt
| From: | Anatol Belski | Date: | Tue, 21 Nov 2017 19:10:18 +0000 |
| Subject: | com php-src: Fixed #75539 and #74183 - preg_last_error no t returning error code after error: ext/pcre/php _pcre.c ext/pcre/tests/bug74183.phpt ext/pc re/tests/bug75539.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100325@lists.php.net to get a copy of this message | ||
Commit: 8fdef981ef940dfc2f1b21cfa3f227150472ad2d
Author: Nester <andrew.nester.dev@gmail.com> Tue, 21 Nov 2017 11:42:22 +0000
Committer: Anatol Belski <ab@php.net> Tue, 21 Nov 2017 20:10:18 +0100
Parents: 702ef2736479af85ce17aec83c6cfc1fecccf326
Branches: PHP-7.0 PHP-7.1 PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8fdef981ef940dfc2f1b21cfa3f227150472ad2d
Log:
Fixed #75539 and #74183 - preg_last_error not returning error code after error
Bugs:
https://bugs.php.net/75539
https://bugs.php.net/74183
Changed paths:
M ext/pcre/php_pcre.c
A ext/pcre/tests/bug74183.phpt
A ext/pcre/tests/bug75539.phpt
Diff:
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 67c373f..c8f13d8 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -356,6 +356,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
#endif
php_error_docref(NULL, E_WARNING,
p < ZSTR_VAL(regex) + ZSTR_LEN(regex) ? "Null byte in regex" : "Empty
regular expression");
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL;
}
@@ -369,6 +370,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
}
#endif
php_error_docref(NULL,E_WARNING, "Delimiter must not be alphanumeric or backslash");
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL;
}
@@ -419,6 +421,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} else {
php_error_docref(NULL,E_WARNING, "No ending matching delimiter '%c' found",
delimiter);
}
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL;
}
@@ -467,6 +470,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
} else {
php_error_docref(NULL,E_WARNING, "Null byte in regex");
}
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
efree(pattern);
#if HAVE_SETLOCALE
if (key != regex) {
@@ -497,6 +501,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
}
#endif
php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %d", error,
erroffset);
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
efree(pattern);
if (tables) {
pefree((void*)tables, 1);
@@ -528,6 +533,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
}
if (error != NULL) {
php_error_docref(NULL, E_WARNING, "Error while studying pattern");
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
}
} else {
extra = NULL;
@@ -564,6 +570,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
}
#endif
php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL;
}
@@ -575,6 +582,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
}
#endif
php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
+ pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
return NULL;
}
diff --git a/ext/pcre/tests/bug74183.phpt b/ext/pcre/tests/bug74183.phpt
new file mode 100644
index 0000000..a230145
--- /dev/null
+++ b/ext/pcre/tests/bug74183.phpt
@@ -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]|
|Ñ|ñ|!|"|%|&|'|´|-|:|;|>|=|<|@|_|,|\{|\}|`|~|á|é|í|ó|ú|Á|É|Í|Ó|Ú|ü|Ü){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)
\ No newline at end of file
diff --git a/ext/pcre/tests/bug75539.phpt b/ext/pcre/tests/bug75539.phpt
new file mode 100644
index 0000000..83f3ef7
--- /dev/null
+++ b/ext/pcre/tests/bug75539.phpt
@@ -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)
\ No newline at end of file