From 27e9c05e8108fe6c184178997176896fb91a3451 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 26 Dec 2018 17:20:13 +0100 Subject: [PATCH] Remove preg_options param from pcre_get_compiled_regex() 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 | 6 +++--- ext/filter/logical_filters.c | 12 ++++++------ ext/pcre/php_pcre.c | 7 ++----- ext/pcre/php_pcre.h | 2 +- ext/standard/browscap.c | 6 +++--- ext/zip/php_zip.c | 6 +++--- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c index d37ce0d255..a270f97eca 100644 --- a/ext/fileinfo/libmagic/softmagic.c +++ b/ext/fileinfo/libmagic/softmagic.c @@ -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); } } diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index 3dcbf21443..c4096593dc 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -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 */ diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index a7c1a93646..da5b69ed55 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -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; diff --git a/ext/pcre/php_pcre.h b/ext/pcre/php_pcre.h index 4c240cbaf9..5afca0b533 100644 --- a/ext/pcre/php_pcre.h +++ b/ext/pcre/php_pcre.h @@ -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; diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index 89bc32cde9..58bc678dca 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -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 diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index a7f63b0526..5aa17fb669 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -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) { -- 2.50.1