Skip to content

Instantly share code, notes, and snippets.

@weltling
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weltling/b77f85be31c55640cb67 to your computer and use it in GitHub Desktop.
Save weltling/b77f85be31c55640cb67 to your computer and use it in GitHub Desktop.
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 55ca8fa..6fdde04 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -758,7 +758,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
/* If subpatterns array has been passed, fill it in with values. */
if (subpats != NULL) {
/* Try to get the list of substrings and display a warning if failed. */
- if (pcre_get_substring_list(subject, offsets, count, &stringlist) < 0) {
+ if (offsets[1] - offsets[0] < 0 || pcre_get_substring_list(subject, offsets, count, &stringlist) < 0) {
if (subpat_names) {
efree(subpat_names);
}
@@ -1177,7 +1177,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
piece = subject + start_offset;
/* if (EXPECTED(count > 0 && (limit == -1 || limit > 0))) */
- if (EXPECTED(count > 0 && limit)) {
+ if (EXPECTED(count > 0 && offsets[1] - offsets[0] >= 0 && limit)) {
if (UNEXPECTED(replace_count)) {
++*replace_count;
}
@@ -1799,7 +1799,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec
}
/* If something matched */
- if (count > 0) {
+ if (count > 0 && offsets[1] - offsets[0] >= 0) {
if (!no_empty || &subject[offsets[0]] != last_match) {
if (offset_capture) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment