]> granicus.if.org Git - php/commitdiff
Remove preg_options param from pcre_get_compiled_regex()
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Dec 2018 16:20:13 +0000 (17:20 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Dec 2018 16:20:13 +0000 (17:20 +0100)
This parameter is always zero and not necessary to call pcre2_match.

I'm leaving the parameter behind on the _ex() variant, so the preg_flags
are still accessible in some way.

ext/fileinfo/libmagic/softmagic.c
ext/filter/logical_filters.c
ext/pcre/php_pcre.c
ext/pcre/php_pcre.h
ext/standard/browscap.c
ext/zip/php_zip.c

index d37ce0d255c5397144aa174cfa223a0614d6a28b..a270f97eca99a1d195195d9dbd11dbcb0a0caf42 100644 (file)
@@ -423,7 +423,7 @@ private int
 check_fmt(struct magic_set *ms, const char *fmt)
 {
        pcre2_code *pce;
-       uint32_t re_options, capture_count;
+       uint32_t capture_count;
        int rv = -1;
        zend_string *pattern;
 
@@ -432,12 +432,12 @@ check_fmt(struct magic_set *ms, const char *fmt)
 
        (void)setlocale(LC_CTYPE, "C");
        pattern = zend_string_init("~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, 0);
-       if ((pce = pcre_get_compiled_regex(pattern, &capture_count, &re_options)) == NULL) {
+       if ((pce = pcre_get_compiled_regex(pattern, &capture_count)) == NULL) {
                rv = -1;
        } else {
                pcre2_match_data *match_data = php_pcre_create_match_data(capture_count, pce);
                if (match_data) {
-                       rv = pcre2_match(pce, (PCRE2_SPTR)fmt, strlen(fmt), 0, re_options, match_data, php_pcre_mctx()) > 0;
+                       rv = pcre2_match(pce, (PCRE2_SPTR)fmt, strlen(fmt), 0, 0, match_data, php_pcre_mctx()) > 0;
                        php_pcre_free_match_data(match_data);
                }
        }
index 3dcbf21443130399d2fdfe0f94dd29950c83eaa7..c4096593dcc51d56eeaffe116ba5805c95b9371c 100644 (file)
@@ -444,7 +444,7 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
        int regexp_set;
        pcre2_code *re = NULL;
        pcre2_match_data *match_data = NULL;
-       uint32_t preg_options, capture_count;
+       uint32_t capture_count;
        int rc;
 
        /* Parse options */
@@ -455,7 +455,7 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
                RETURN_VALIDATION_FAILED
        }
 
-       re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options);
+       re = pcre_get_compiled_regex(regexp, &capture_count);
        if (!re) {
                RETURN_VALIDATION_FAILED
        }
@@ -463,7 +463,7 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
        if (!match_data) {
                RETURN_VALIDATION_FAILED
        }
-       rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, preg_options, match_data, php_pcre_mctx());
+       rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, 0, match_data, php_pcre_mctx());
        php_pcre_free_match_data(match_data);
 
        /* 0 means that the vector is too small to hold all the captured substring offsets */
@@ -624,7 +624,7 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
         */
        pcre2_code *re = NULL;
        pcre2_match_data *match_data = NULL;
-       uint32_t preg_options = 0, capture_count;
+       uint32_t capture_count;
        zend_string *sregexp;
        int rc;
        const char regexp0[] = "/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E\\pL\\pN]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F\\pL\\pN]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E\\pL\\pN]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F\\pL\\pN]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iDu";
@@ -646,7 +646,7 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
        }
 
        sregexp = zend_string_init(regexp, regexp_len, 0);
-       re = pcre_get_compiled_regex(sregexp, &capture_count, &preg_options);
+       re = pcre_get_compiled_regex(sregexp, &capture_count);
        zend_string_release_ex(sregexp, 0);
        if (!re) {
                RETURN_VALIDATION_FAILED
@@ -655,7 +655,7 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
        if (!match_data) {
                RETURN_VALIDATION_FAILED
        }
-       rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, preg_options, match_data, php_pcre_mctx());
+       rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, 0, match_data, php_pcre_mctx());
        php_pcre_free_match_data(match_data);
 
        /* 0 means that the vector is too small to hold all the captured substring offsets */
index a7c1a93646dc3c8f5acc8315585db074a1f4f1f6..da5b69ed5553dbd185db75af904ad0ee6d9873a3 100644 (file)
@@ -862,13 +862,10 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
 
 /* {{{ pcre_get_compiled_regex
  */
-PHPAPI pcre2_code *pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count, uint32_t *preg_options)
+PHPAPI pcre2_code *pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count)
 {
        pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex);
 
-       if (preg_options) {
-               *preg_options = 0;
-       }
        if (capture_count) {
                *capture_count = pce ? pce->capture_count : 0;
        }
@@ -884,7 +881,7 @@ PHPAPI pcre2_code* pcre_get_compiled_regex_ex(zend_string *regex, uint32_t *capt
        pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex);
 
        if (preg_options) {
-               *preg_options = 0;
+               *preg_options = pce ? pce->preg_options : 0;
        }
        if (compile_options) {
                *compile_options = pce ? pce->compile_options : 0;
index 4c240cbaf9adc4494a814220ac3652c91998f424..5afca0b533fc62da8fe9e0627f3976af785d383a 100644 (file)
@@ -32,7 +32,7 @@
 #endif
 
 PHPAPI zend_string *php_pcre_replace(zend_string *regex, zend_string *subject_str, char *subject, size_t subject_len, zend_string *replace_str, size_t limit, size_t *replace_count);
-PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count, uint32_t *options);
+PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count);
 PHPAPI pcre2_code* pcre_get_compiled_regex_ex(zend_string *regex, uint32_t *capture_count, uint32_t *preg_options, uint32_t *coptions);
 
 extern zend_module_entry pcre_module_entry;
index 89bc32cde9891d2f09048a2feecb661e14da1845..58bc678dca7e91f87dcdb59fbe0058f0b4d189b3 100644 (file)
@@ -573,7 +573,7 @@ static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, b
 
        pcre2_code *re;
        pcre2_match_data *match_data;
-       uint32_t re_options, capture_count;
+       uint32_t capture_count;
        int rc;
 
        /* Agent name too short */
@@ -616,7 +616,7 @@ static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, b
        }
 
        regex = browscap_convert_pattern(entry->pattern, 0);
-       re = pcre_get_compiled_regex(regex, &capture_count, &re_options);
+       re = pcre_get_compiled_regex(regex, &capture_count);
        if (re == NULL) {
                ZSTR_ALLOCA_FREE(pattern_lc, use_heap);
                zend_string_release(regex);
@@ -629,7 +629,7 @@ static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, b
                zend_string_release(regex);
                return 0;
        }
-       rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(agent_name), ZSTR_LEN(agent_name), 0, re_options, match_data, php_pcre_mctx());
+       rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(agent_name), ZSTR_LEN(agent_name), 0, 0, match_data, php_pcre_mctx());
        php_pcre_free_match_data(match_data);
        if (PCRE2_ERROR_NOMATCH != rc) {
                /* If we've found a possible browser, we need to do a comparison of the
index a7f63b05261ebd8f645481cff7000acd9ada7f40..5aa17fb6691ffd93f3f81d8551e5081caa4422d1 100644 (file)
@@ -654,10 +654,10 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
        if (files_cnt > 0) {
                pcre2_code *re = NULL;
                pcre2_match_data *match_data = NULL;
-               uint32_t preg_options = 0, i, capture_count;
+               uint32_t i, capture_count;
                int rc;
 
-               re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options);
+               re = pcre_get_compiled_regex(regexp, &capture_count);
                if (!re) {
                        php_error_docref(NULL, E_WARNING, "Invalid expression");
                        return -1;
@@ -703,7 +703,7 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
                                zend_string_release_ex(namelist[i], 0);
                                continue;
                        }
-                       rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, preg_options, match_data, mctx);
+                       rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, 0, match_data, mctx);
                        php_pcre_free_match_data(match_data);
                        /* 0 means that the vector is too small to hold all the captured substring offsets */
                        if (rc < 0) {