Skip to content

Commit 27e9c05

Browse files
committed
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.
1 parent fc30c0f commit 27e9c05

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

ext/fileinfo/libmagic/softmagic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ private int
423423
check_fmt(struct magic_set *ms, const char *fmt)
424424
{
425425
pcre2_code *pce;
426-
uint32_t re_options, capture_count;
426+
uint32_t capture_count;
427427
int rv = -1;
428428
zend_string *pattern;
429429

@@ -432,12 +432,12 @@ check_fmt(struct magic_set *ms, const char *fmt)
432432

433433
(void)setlocale(LC_CTYPE, "C");
434434
pattern = zend_string_init("~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, 0);
435-
if ((pce = pcre_get_compiled_regex(pattern, &capture_count, &re_options)) == NULL) {
435+
if ((pce = pcre_get_compiled_regex(pattern, &capture_count)) == NULL) {
436436
rv = -1;
437437
} else {
438438
pcre2_match_data *match_data = php_pcre_create_match_data(capture_count, pce);
439439
if (match_data) {
440-
rv = pcre2_match(pce, (PCRE2_SPTR)fmt, strlen(fmt), 0, re_options, match_data, php_pcre_mctx()) > 0;
440+
rv = pcre2_match(pce, (PCRE2_SPTR)fmt, strlen(fmt), 0, 0, match_data, php_pcre_mctx()) > 0;
441441
php_pcre_free_match_data(match_data);
442442
}
443443
}

ext/filter/logical_filters.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
444444
int regexp_set;
445445
pcre2_code *re = NULL;
446446
pcre2_match_data *match_data = NULL;
447-
uint32_t preg_options, capture_count;
447+
uint32_t capture_count;
448448
int rc;
449449

450450
/* Parse options */
@@ -455,15 +455,15 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
455455
RETURN_VALIDATION_FAILED
456456
}
457457

458-
re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options);
458+
re = pcre_get_compiled_regex(regexp, &capture_count);
459459
if (!re) {
460460
RETURN_VALIDATION_FAILED
461461
}
462462
match_data = php_pcre_create_match_data(capture_count, re);
463463
if (!match_data) {
464464
RETURN_VALIDATION_FAILED
465465
}
466-
rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, preg_options, match_data, php_pcre_mctx());
466+
rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, 0, match_data, php_pcre_mctx());
467467
php_pcre_free_match_data(match_data);
468468

469469
/* 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) /* {{{ */
624624
*/
625625
pcre2_code *re = NULL;
626626
pcre2_match_data *match_data = NULL;
627-
uint32_t preg_options = 0, capture_count;
627+
uint32_t capture_count;
628628
zend_string *sregexp;
629629
int rc;
630630
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) /* {{{ */
646646
}
647647

648648
sregexp = zend_string_init(regexp, regexp_len, 0);
649-
re = pcre_get_compiled_regex(sregexp, &capture_count, &preg_options);
649+
re = pcre_get_compiled_regex(sregexp, &capture_count);
650650
zend_string_release_ex(sregexp, 0);
651651
if (!re) {
652652
RETURN_VALIDATION_FAILED
@@ -655,7 +655,7 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
655655
if (!match_data) {
656656
RETURN_VALIDATION_FAILED
657657
}
658-
rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, preg_options, match_data, php_pcre_mctx());
658+
rc = pcre2_match(re, (PCRE2_SPTR)Z_STRVAL_P(value), Z_STRLEN_P(value), 0, 0, match_data, php_pcre_mctx());
659659
php_pcre_free_match_data(match_data);
660660

661661
/* 0 means that the vector is too small to hold all the captured substring offsets */

ext/pcre/php_pcre.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,13 +862,10 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
862862

863863
/* {{{ pcre_get_compiled_regex
864864
*/
865-
PHPAPI pcre2_code *pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count, uint32_t *preg_options)
865+
PHPAPI pcre2_code *pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count)
866866
{
867867
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex);
868868

869-
if (preg_options) {
870-
*preg_options = 0;
871-
}
872869
if (capture_count) {
873870
*capture_count = pce ? pce->capture_count : 0;
874871
}
@@ -884,7 +881,7 @@ PHPAPI pcre2_code* pcre_get_compiled_regex_ex(zend_string *regex, uint32_t *capt
884881
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex);
885882

886883
if (preg_options) {
887-
*preg_options = 0;
884+
*preg_options = pce ? pce->preg_options : 0;
888885
}
889886
if (compile_options) {
890887
*compile_options = pce ? pce->compile_options : 0;

ext/pcre/php_pcre.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#endif
3333

3434
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);
35-
PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count, uint32_t *options);
35+
PHPAPI pcre2_code* pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count);
3636
PHPAPI pcre2_code* pcre_get_compiled_regex_ex(zend_string *regex, uint32_t *capture_count, uint32_t *preg_options, uint32_t *coptions);
3737

3838
extern zend_module_entry pcre_module_entry;

ext/standard/browscap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, b
573573

574574
pcre2_code *re;
575575
pcre2_match_data *match_data;
576-
uint32_t re_options, capture_count;
576+
uint32_t capture_count;
577577
int rc;
578578

579579
/* Agent name too short */
@@ -616,7 +616,7 @@ static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, b
616616
}
617617

618618
regex = browscap_convert_pattern(entry->pattern, 0);
619-
re = pcre_get_compiled_regex(regex, &capture_count, &re_options);
619+
re = pcre_get_compiled_regex(regex, &capture_count);
620620
if (re == NULL) {
621621
ZSTR_ALLOCA_FREE(pattern_lc, use_heap);
622622
zend_string_release(regex);
@@ -629,7 +629,7 @@ static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, b
629629
zend_string_release(regex);
630630
return 0;
631631
}
632-
rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(agent_name), ZSTR_LEN(agent_name), 0, re_options, match_data, php_pcre_mctx());
632+
rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(agent_name), ZSTR_LEN(agent_name), 0, 0, match_data, php_pcre_mctx());
633633
php_pcre_free_match_data(match_data);
634634
if (PCRE2_ERROR_NOMATCH != rc) {
635635
/* If we've found a possible browser, we need to do a comparison of the

ext/zip/php_zip.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,10 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
654654
if (files_cnt > 0) {
655655
pcre2_code *re = NULL;
656656
pcre2_match_data *match_data = NULL;
657-
uint32_t preg_options = 0, i, capture_count;
657+
uint32_t i, capture_count;
658658
int rc;
659659

660-
re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options);
660+
re = pcre_get_compiled_regex(regexp, &capture_count);
661661
if (!re) {
662662
php_error_docref(NULL, E_WARNING, "Invalid expression");
663663
return -1;
@@ -703,7 +703,7 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
703703
zend_string_release_ex(namelist[i], 0);
704704
continue;
705705
}
706-
rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, preg_options, match_data, mctx);
706+
rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, 0, match_data, mctx);
707707
php_pcre_free_match_data(match_data);
708708
/* 0 means that the vector is too small to hold all the captured substring offsets */
709709
if (rc < 0) {

0 commit comments

Comments
 (0)