]> granicus.if.org Git - php/commitdiff
Merge branch 'PHP-7.2'
authorAnatol Belski <ab@php.net>
Tue, 21 Nov 2017 19:15:30 +0000 (20:15 +0100)
committerAnatol Belski <ab@php.net>
Tue, 21 Nov 2017 19:15:30 +0000 (20:15 +0100)
* PHP-7.2:
  Fixed #75539 and #74183 - preg_last_error not returning error code after error

1  2 
ext/pcre/php_pcre.c

index f23202ba1825257943df36026cc39632a862a122,aa2695ea2c64c7b646baadd173c0ffd253bb3a1a..fd9f20d4a3f66166474c5283066bd1b9bb5f233c
@@@ -712,8 -506,8 +716,9 @@@ PHPAPI pcre_cache_entry* pcre_get_compi
                        zend_string_release(key);
                }
  #endif
 -              php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %d", error, erroffset);
 +              pcre2_get_error_message(errnumber, error, sizeof(error));
 +              php_error_docref(NULL,E_WARNING, "Compilation failed: %s at offset %zu", error, erroffset);
+               pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
                efree(pattern);
                if (tables) {
                        pefree((void*)tables, 1);
  #ifdef HAVE_PCRE_JIT_SUPPORT
        if (PCRE_G(jit)) {
                /* Enable PCRE JIT compiler */
 -              do_study = 1;
 -              soptions |= PCRE_STUDY_JIT_COMPILE;
 -      }
 -#endif
 -
 -      /* If study option was specified, study the pattern and
 -         store the result in extra for passing to pcre_exec. */
 -      if (do_study) {
 -              extra = pcre_study(re, soptions, &error);
 -              if (extra) {
 -                      extra->flags |= PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
 -                      extra->match_limit = (unsigned long)PCRE_G(backtrack_limit);
 -                      extra->match_limit_recursion = (unsigned long)PCRE_G(recursion_limit);
 -#ifdef HAVE_PCRE_JIT_SUPPORT
 -                      if (PCRE_G(jit) && jit_stack) {
 -                              pcre_assign_jit_stack(extra, NULL, jit_stack);
 +              rc = pcre2_jit_compile(re, PCRE2_JIT_COMPLETE);
 +              if (EXPECTED(rc >= 0)) {
 +                      size_t jit_size = 0;
 +                      if (!pcre2_pattern_info(re, PCRE2_INFO_JITSIZE, &jit_size) && jit_size > 0) {
 +                              poptions |= PREG_JIT;
                        }
 -#endif
 -              }
 -              if (error != NULL) {
 -                      php_error_docref(NULL, E_WARNING, "Error while studying pattern");
 +              } else {
 +                      pcre2_get_error_message(rc, error, sizeof(error));
 +                      php_error_docref(NULL, E_WARNING, "JIT compilation failed: %s", error);
+                       pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
                }
 -      } else {
 -              extra = NULL;
        }
 -
 +#endif
        efree(pattern);
  
        /*
                        zend_string_release(key);
                }
  #endif
 -              php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
 +              php_error_docref(NULL, E_WARNING, "Internal pcre2_pattern_info() error %d", rc);
+               pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
                return NULL;
        }
  
                        zend_string_release(key);
                }
  #endif
 -              php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
 +              php_error_docref(NULL, E_WARNING, "Internal pcre_pattern_info() error %d", rc);
+               pcre_handle_exec_error(PCRE_ERROR_INTERNAL);
                return NULL;
        }