From e6f90ecc27f5d305a0e755da67db75da786f4568 Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Tue, 2 Jul 2013 09:46:30 -0400 Subject: It compiles. Sort-of. In a way. Yeah. But nothing works. Sigh --- ext/pcre/php_pcre.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 7d34d9feb1..0516d742e4 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -875,8 +875,8 @@ static int preg_do_repl_func(zval *function, char *subject, int *offsets, char * if (call_user_function_ex(EG(function_table), NULL, function, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { convert_to_string_ex(&retval_ptr); - *result = estrndup(Z_STRVAL_P(retval_ptr), Z_STRLEN_P(retval_ptr)); - result_len = Z_STRLEN_P(retval_ptr); + *result = estrndup(Z_STRVAL_P(retval_ptr), Z_STRSIZE_P(retval_ptr)); + result_len = Z_STRSIZE_P(retval_ptr); zval_ptr_dtor(&retval_ptr); } else { if (!EG(exception)) { @@ -969,8 +969,8 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, convert_to_string(&retval); /* Save the return value and its length */ - *result = estrndup(Z_STRVAL(retval), Z_STRLEN(retval)); - result_len = Z_STRLEN(retval); + *result = estrndup(Z_STRVAL(retval), Z_STRSIZE(retval)); + result_len = Z_STRSIZE(retval); /* Clean up */ zval_dtor(&retval); @@ -1048,7 +1048,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub } } else { replace = Z_STRVAL_P(replace_val); - replace_len = Z_STRLEN_P(replace_val); + replace_len = Z_STRSIZE_P(replace_val); replace_end = replace + replace_len; } @@ -1261,8 +1261,8 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, /* If regex is an array */ if (Z_TYPE_P(regex) == IS_ARRAY) { /* Duplicate subject string for repeated replacement */ - subject_value = estrndup(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject)); - subject_len = Z_STRLEN_PP(subject); + subject_value = estrndup(Z_STRVAL_PP(subject), Z_STRSIZE_PP(subject)); + subject_len = Z_STRSIZE_PP(subject); *result_len = subject_len; zend_hash_internal_pointer_reset(Z_ARRVAL_P(regex)); @@ -1294,7 +1294,7 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, /* Do the actual replacement and put the result back into subject_value for further replacements. */ if ((result = php_pcre_replace(Z_STRVAL_PP(regex_entry), - Z_STRLEN_PP(regex_entry), + Z_STRSIZE_PP(regex_entry), subject_value, subject_len, replace_value, @@ -1316,9 +1316,9 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, return subject_value; } else { result = php_pcre_replace(Z_STRVAL_P(regex), - Z_STRLEN_P(regex), + Z_STRSIZE_P(regex), Z_STRVAL_PP(subject), - Z_STRLEN_PP(subject), + Z_STRSIZE_PP(subject), replace, is_callable_replace, result_len, @@ -1810,7 +1810,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return /* Perform the match */ count = pcre_exec(pce->re, extra, Z_STRVAL(subject), - Z_STRLEN(subject), 0, + Z_STRSIZE(subject), 0, 0, offsets, size_offsets); /* Check for too many substrings condition. */ -- cgit v1.2.1 From 6484eaf77ee80d43297e202b113ab3976f25a708 Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Tue, 2 Jul 2013 10:20:01 -0400 Subject: Better test coverage --- ext/pcre/php_pcre.c | 78 ++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 0516d742e4..7bc5427249 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -226,14 +226,14 @@ static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_D /* {{{ pcre_get_compiled_regex_cache */ -PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC) +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, zend_str_size_int regex_len TSRMLS_DC) { pcre *re = NULL; pcre_extra *extra; int coptions = 0; int soptions = 0; const char *error; - int erroffset; + zend_str_size erroffset; char delimiter; char start_delimiter; char end_delimiter; @@ -508,7 +508,7 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr /* }}} */ /* {{{ add_offset_pair */ -static inline void add_offset_pair(zval *result, char *str, int len, int offset, char *name) +static inline void add_offset_pair(zval *result, char *str, zend_str_size_int len, zend_str_size_int offset, char *name) { zval *match_pair; @@ -533,14 +533,14 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * /* parameters */ char *regex; /* Regular expression */ char *subject; /* String to match against */ - int regex_len; - int subject_len; + zend_str_size regex_len; + zend_str_size subject_len; pcre_cache_entry *pce; /* Compiled regular expression */ zval *subpats = NULL; /* Array for subpatterns */ long flags = 0; /* Match control flags */ long start_offset = 0; /* Where the new search starts */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|zll", ®ex, ®ex_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|zll", ®ex, ®ex_len, &subject, &subject_len, &subpats, &flags, &start_offset) == FAILURE) { RETURN_FALSE; } @@ -556,7 +556,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * /* }}} */ /* {{{ php_pcre_match_impl() */ -PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, +PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, zval *subpats, int global, int use_flags, long flags, long start_offset TSRMLS_DC) { zval *result_set, /* Holds a set of subpatterns after @@ -855,12 +855,12 @@ static int preg_get_backref(char **str, int *backref) /* {{{ preg_do_repl_func */ -static int preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) +static int preg_do_repl_func(zval *function, char *subject, zend_str_size_int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) { zval *retval_ptr; /* Function return value */ zval **args[1]; /* Argument to pass to function */ zval *subpats; /* Captured subpatterns */ - int result_len; /* Return value length */ + zend_str_size result_len; /* Return value length */ int i; MAKE_STD_ZVAL(subpats); @@ -894,8 +894,8 @@ static int preg_do_repl_func(zval *function, char *subject, int *offsets, char * /* {{{ preg_do_eval */ -static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, - int *offsets, int count, char **result TSRMLS_DC) +static int preg_do_eval(char *eval_str, zend_str_size_int eval_str_len, char *subject, + zend_str_size_int *offsets, int count, char **result TSRMLS_DC) { zval retval; /* Return value from evaluation */ char *eval_str_end, /* End of eval string */ @@ -904,10 +904,10 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, *walk, /* Used to walk the code string */ *segment, /* Start of segment to append while walking */ walk_last; /* Last walked character */ - int match_len; /* Length of the match */ - int esc_match_len; /* Length of the quote-escaped match */ - int result_len; /* Length of the result of the evaluation */ - int backref; /* Current backref */ + zend_str_size match_len; /* Length of the match */ + zend_str_size esc_match_len; /* Length of the quote-escaped match */ + zend_str_size result_len; /* Length of the result of the evaluation */ + zend_str_size backref; /* Current backref */ char *compiled_string_description; smart_str code = {0}; @@ -982,10 +982,10 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, /* {{{ php_pcre_replace */ -PHPAPI char *php_pcre_replace(char *regex, int regex_len, - char *subject, int subject_len, +PHPAPI char *php_pcre_replace(char *regex, zend_str_size_int regex_len, + char *subject, zend_str_size_int subject_len, zval *replace_val, int is_callable_replace, - int *result_len, int limit, int *replace_count TSRMLS_DC) + zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_cache_entry *pce; /* Compiled regular expression */ @@ -1000,8 +1000,8 @@ PHPAPI char *php_pcre_replace(char *regex, int regex_len, /* }}} */ /* {{{ php_pcre_replace_impl() */ -PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, - int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC) +PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *replace_val, + int is_callable_replace, zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_extra *extra = pce->extra;/* Holds results of studying */ pcre_extra extra_data; /* Used locally for exec options */ @@ -1011,16 +1011,16 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub char **subpat_names; /* Array for named subpatterns */ int num_subpats; /* Number of captured subpatterns */ int size_offsets; /* Size of the offsets array */ - int new_len; /* Length of needed storage */ - int alloc_len; /* Actual allocated length */ - int eval_result_len=0; /* Length of the eval'ed or + zend_str_size new_len; /* Length of needed storage */ + zend_str_size alloc_len; /* Actual allocated length */ + zend_str_size eval_result_len=0; /* Length of the eval'ed or function-returned string */ - int match_len; /* Length of the current match */ - int backref; /* Backreference number */ + zend_str_size match_len; /* Length of the current match */ + zend_str_size backref; /* Backreference number */ int eval; /* If the replacement string should be eval'ed */ - int start_offset; /* Where the new search starts */ + zend_str_size start_offset; /* Where the new search starts */ int g_notempty=0; /* If the match should not be empty */ - int replace_len=0; /* Length of replacement string */ + zend_str_size replace_len=0; /* Length of replacement string */ char *result, /* Result of replacement */ *replace=NULL, /* Replacement string */ *new_buf, /* Temporary buffer for re-allocation */ @@ -1243,7 +1243,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub /* {{{ php_replace_in_subject */ -static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, int *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) +static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, zend_str_size_int *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) { zval **regex_entry, **replace_entry = NULL, @@ -1251,7 +1251,7 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, empty_replace; char *subject_value, *result; - int subject_len; + zend_str_size subject_len; /* Make sure we're dealing with strings. */ convert_to_string_ex(subject); @@ -1339,7 +1339,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl **subject_entry, **zcount = NULL; char *result; - int result_len; + zend_str_size result_len; int limit_val = -1; long limit = -1; char *string_key; @@ -1459,14 +1459,14 @@ static PHP_FUNCTION(preg_split) { char *regex; /* Regular expression */ char *subject; /* String to match against */ - int regex_len; - int subject_len; + zend_str_size regex_len; + zend_str_size subject_len; long limit_val = -1;/* Integer value of limit */ long flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get function parameters and do error checking */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", ®ex, ®ex_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ll", ®ex, ®ex_len, &subject, &subject_len, &limit_val, &flags) == FAILURE) { RETURN_FALSE; } @@ -1482,7 +1482,7 @@ static PHP_FUNCTION(preg_split) /* {{{ php_pcre_split */ -PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, +PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, long limit_val, long flags TSRMLS_DC) { pcre_extra *extra = NULL; /* Holds results of studying */ @@ -1653,10 +1653,10 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec Quote regular expression characters plus an optional character */ static PHP_FUNCTION(preg_quote) { - int in_str_len; + zend_str_size in_str_len; char *in_str; /* Input string argument */ char *in_str_end; /* End of the input string */ - int delim_len = 0; + zend_str_size delim_len = 0; char *delim = NULL; /* Additional delimiter argument */ char *out_str, /* Output string with quoted characters */ *p, /* Iterator for input string */ @@ -1666,7 +1666,7 @@ static PHP_FUNCTION(preg_quote) zend_bool quote_delim = 0; /* Whether to quote additional delim char */ /* Get the arguments and check for errors */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &in_str, &in_str_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &in_str, &in_str_len, &delim, &delim_len) == FAILURE) { return; } @@ -1741,13 +1741,13 @@ static PHP_FUNCTION(preg_quote) static PHP_FUNCTION(preg_grep) { char *regex; /* Regular expression */ - int regex_len; + zend_str_size regex_len; zval *input; /* Input array */ long flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get arguments and do error checking */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|l", ®ex, ®ex_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sa|l", ®ex, ®ex_len, &input, &flags) == FAILURE) { return; } -- cgit v1.2.1 From 0cd95c1ee0092cd9528b08e25e5dcbdfe116dedd Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Tue, 2 Jul 2013 11:27:48 -0400 Subject: Get basic language tests to all pass (minus xfails) --- ext/pcre/php_pcre.c | 76 ++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 7bc5427249..cf296fc434 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -226,14 +226,14 @@ static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_D /* {{{ pcre_get_compiled_regex_cache */ -PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, zend_str_size_int regex_len TSRMLS_DC) +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC) { pcre *re = NULL; pcre_extra *extra; int coptions = 0; int soptions = 0; const char *error; - zend_str_size erroffset; + int erroffset; char delimiter; char start_delimiter; char end_delimiter; @@ -399,7 +399,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, zend_str_siz re = pcre_compile(pattern, coptions, &error, - &erroffset, + (int *) &erroffset, tables); if (re == NULL) { @@ -508,7 +508,7 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr /* }}} */ /* {{{ add_offset_pair */ -static inline void add_offset_pair(zval *result, char *str, zend_str_size_int len, zend_str_size_int offset, char *name) +static inline void add_offset_pair(zval *result, char *str, zend_str_size_int len, long offset, char *name) { zval *match_pair; @@ -546,17 +546,17 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * } /* Compile regex or get it from cache. */ - if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { + if ((pce = pcre_get_compiled_regex_cache(regex, (int) regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } - php_pcre_match_impl(pce, subject, subject_len, return_value, subpats, + php_pcre_match_impl(pce, subject, (int) subject_len, return_value, subpats, global, ZEND_NUM_ARGS() >= 4, flags, start_offset TSRMLS_CC); } /* }}} */ /* {{{ php_pcre_match_impl() */ -PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, +PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, zval *subpats, int global, int use_flags, long flags, long start_offset TSRMLS_DC) { zval *result_set, /* Holds a set of subpatterns after @@ -855,12 +855,12 @@ static int preg_get_backref(char **str, int *backref) /* {{{ preg_do_repl_func */ -static int preg_do_repl_func(zval *function, char *subject, zend_str_size_int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) +static int preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) { zval *retval_ptr; /* Function return value */ zval **args[1]; /* Argument to pass to function */ zval *subpats; /* Captured subpatterns */ - zend_str_size result_len; /* Return value length */ + int result_len; /* Return value length */ int i; MAKE_STD_ZVAL(subpats); @@ -894,8 +894,8 @@ static int preg_do_repl_func(zval *function, char *subject, zend_str_size_int *o /* {{{ preg_do_eval */ -static int preg_do_eval(char *eval_str, zend_str_size_int eval_str_len, char *subject, - zend_str_size_int *offsets, int count, char **result TSRMLS_DC) +static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, + int *offsets, int count, char **result TSRMLS_DC) { zval retval; /* Return value from evaluation */ char *eval_str_end, /* End of eval string */ @@ -904,10 +904,10 @@ static int preg_do_eval(char *eval_str, zend_str_size_int eval_str_len, char *su *walk, /* Used to walk the code string */ *segment, /* Start of segment to append while walking */ walk_last; /* Last walked character */ - zend_str_size match_len; /* Length of the match */ - zend_str_size esc_match_len; /* Length of the quote-escaped match */ - zend_str_size result_len; /* Length of the result of the evaluation */ - zend_str_size backref; /* Current backref */ + zend_str_size match_len; /* Length of the match */ + zend_str_size esc_match_len; /* Length of the quote-escaped match */ + zend_str_size result_len; /* Length of the result of the evaluation */ + int backref; /* Current backref */ char *compiled_string_description; smart_str code = {0}; @@ -982,10 +982,10 @@ static int preg_do_eval(char *eval_str, zend_str_size_int eval_str_len, char *su /* {{{ php_pcre_replace */ -PHPAPI char *php_pcre_replace(char *regex, zend_str_size_int regex_len, - char *subject, zend_str_size_int subject_len, +PHPAPI char *php_pcre_replace(char *regex, int regex_len, + char *subject, int subject_len, zval *replace_val, int is_callable_replace, - zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) + int *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_cache_entry *pce; /* Compiled regular expression */ @@ -1000,27 +1000,27 @@ PHPAPI char *php_pcre_replace(char *regex, zend_str_size_int regex_len, /* }}} */ /* {{{ php_pcre_replace_impl() */ -PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *replace_val, - int is_callable_replace, zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) +PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, + int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_extra *extra = pce->extra;/* Holds results of studying */ pcre_extra extra_data; /* Used locally for exec options */ int exoptions = 0; /* Execution options */ int count = 0; /* Count of matched subpatterns */ - int *offsets; /* Array of subpattern offsets */ + int *offsets; /* Array of subpattern offsets */ char **subpat_names; /* Array for named subpatterns */ int num_subpats; /* Number of captured subpatterns */ int size_offsets; /* Size of the offsets array */ - zend_str_size new_len; /* Length of needed storage */ - zend_str_size alloc_len; /* Actual allocated length */ - zend_str_size eval_result_len=0; /* Length of the eval'ed or + int new_len; /* Length of needed storage */ + int alloc_len; /* Actual allocated length */ + int eval_result_len=0; /* Length of the eval'ed or function-returned string */ - zend_str_size match_len; /* Length of the current match */ - zend_str_size backref; /* Backreference number */ + int match_len; /* Length of the current match */ + int backref; /* Backreference number */ int eval; /* If the replacement string should be eval'ed */ - zend_str_size start_offset; /* Where the new search starts */ + int start_offset; /* Where the new search starts */ int g_notempty=0; /* If the match should not be empty */ - zend_str_size replace_len=0; /* Length of replacement string */ + int replace_len=0; /* Length of replacement string */ char *result, /* Result of replacement */ *replace=NULL, /* Replacement string */ *new_buf, /* Temporary buffer for re-allocation */ @@ -1243,7 +1243,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st /* {{{ php_replace_in_subject */ -static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, zend_str_size_int *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) +static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, int *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) { zval **regex_entry, **replace_entry = NULL, @@ -1251,7 +1251,7 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, empty_replace; char *subject_value, *result; - zend_str_size subject_len; + int subject_len; /* Make sure we're dealing with strings. */ convert_to_string_ex(subject); @@ -1339,7 +1339,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl **subject_entry, **zcount = NULL; char *result; - zend_str_size result_len; + int result_len; int limit_val = -1; long limit = -1; char *string_key; @@ -1397,11 +1397,11 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl switch(zend_hash_get_current_key(Z_ARRVAL_PP(subject), &string_key, &num_key, 0)) { case HASH_KEY_IS_STRING: - add_assoc_stringl(return_value, string_key, result, result_len, 0); + add_assoc_stringl(return_value, string_key, result, (zend_str_size) result_len, 0); break; case HASH_KEY_IS_LONG: - add_index_stringl(return_value, num_key, result, result_len, 0); + add_index_stringl(return_value, num_key, result, (zend_str_size) result_len, 0); break; } } else { @@ -1415,7 +1415,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl old_replace_count = replace_count; if ((result = php_replace_in_subject(*regex, *replace, subject, &result_len, limit_val, is_callable_replace, &replace_count TSRMLS_CC)) != NULL) { if (!is_filter || replace_count > old_replace_count) { - RETVAL_STRINGL(result, result_len, 0); + RETVAL_STRINGL(result, (zend_str_size) result_len, 0); } else { efree(result); } @@ -1472,17 +1472,17 @@ static PHP_FUNCTION(preg_split) } /* Compile regex or get it from cache. */ - if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { + if ((pce = pcre_get_compiled_regex_cache(regex, (int) regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } - php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC); + php_pcre_split_impl(pce, subject, (int) subject_len, return_value, limit_val, flags TSRMLS_CC); } /* }}} */ /* {{{ php_pcre_split */ -PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, +PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, long limit_val, long flags TSRMLS_DC) { pcre_extra *extra = NULL; /* Holds results of studying */ @@ -1753,7 +1753,7 @@ static PHP_FUNCTION(preg_grep) } /* Compile regex or get it from cache. */ - if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { + if ((pce = pcre_get_compiled_regex_cache(regex, (int) regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } -- cgit v1.2.1 From b24f226e936192180ec7950788e00debfdb60653 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 23 Aug 2013 00:56:10 -0700 Subject: replaced arg formats in pcre --- ext/pcre/php_pcre.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index cf296fc434..5e108f15a5 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -537,10 +537,10 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * zend_str_size subject_len; pcre_cache_entry *pce; /* Compiled regular expression */ zval *subpats = NULL; /* Array for subpatterns */ - long flags = 0; /* Match control flags */ - long start_offset = 0; /* Where the new search starts */ + php_int_t flags = 0; /* Match control flags */ + php_int_t start_offset = 0; /* Where the new search starts */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|zll", ®ex, ®ex_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|zii", ®ex, ®ex_len, &subject, &subject_len, &subpats, &flags, &start_offset) == FAILURE) { RETURN_FALSE; } @@ -1341,14 +1341,14 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl char *result; int result_len; int limit_val = -1; - long limit = -1; + php_int_t limit = -1; char *string_key; ulong num_key; char *callback_name; int replace_count=0, old_replace_count; /* Get function parameters and do error-checking. */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZZ|lZ", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZZ|iZ", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { return; } @@ -1461,12 +1461,12 @@ static PHP_FUNCTION(preg_split) char *subject; /* String to match against */ zend_str_size regex_len; zend_str_size subject_len; - long limit_val = -1;/* Integer value of limit */ - long flags = 0; /* Match control flags */ + php_int_t limit_val = -1;/* Integer value of limit */ + php_int_t flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get function parameters and do error checking */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ll", ®ex, ®ex_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ii", ®ex, ®ex_len, &subject, &subject_len, &limit_val, &flags) == FAILURE) { RETURN_FALSE; } @@ -1743,11 +1743,11 @@ static PHP_FUNCTION(preg_grep) char *regex; /* Regular expression */ zend_str_size regex_len; zval *input; /* Input array */ - long flags = 0; /* Match control flags */ + php_int_t flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get arguments and do error checking */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sa|l", ®ex, ®ex_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sa|i", ®ex, ®ex_len, &input, &flags) == FAILURE) { return; } -- cgit v1.2.1 From 69ea580aad2932921b49e8fab89ab851e08a63da Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 23 Aug 2013 06:37:51 -0700 Subject: fixed ext/pcre internal stuff Now only the flaw is pcrelib itself as it works with int for string length and offsets. Bigger stuff won't work anyway, but if there are some issue there are just a few places like pcre_exec() where we can explicitly cast to int. --- ext/pcre/php_pcre.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 5e108f15a5..09713eb7ad 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -226,7 +226,7 @@ static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_D /* {{{ pcre_get_compiled_regex_cache */ -PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC) +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, zend_str_size_int regex_len TSRMLS_DC) { pcre *re = NULL; pcre_extra *extra; @@ -546,17 +546,17 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * } /* Compile regex or get it from cache. */ - if ((pce = pcre_get_compiled_regex_cache(regex, (int) regex_len TSRMLS_CC)) == NULL) { + if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } - php_pcre_match_impl(pce, subject, (int) subject_len, return_value, subpats, + php_pcre_match_impl(pce, subject, subject_len, return_value, subpats, global, ZEND_NUM_ARGS() >= 4, flags, start_offset TSRMLS_CC); } /* }}} */ /* {{{ php_pcre_match_impl() */ -PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, +PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, zval *subpats, int global, int use_flags, long flags, long start_offset TSRMLS_DC) { zval *result_set, /* Holds a set of subpatterns after @@ -855,12 +855,12 @@ static int preg_get_backref(char **str, int *backref) /* {{{ preg_do_repl_func */ -static int preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) +static zend_str_size_int preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) { zval *retval_ptr; /* Function return value */ zval **args[1]; /* Argument to pass to function */ zval *subpats; /* Captured subpatterns */ - int result_len; /* Return value length */ + zend_str_size_int result_len; /* Return value length */ int i; MAKE_STD_ZVAL(subpats); @@ -894,7 +894,7 @@ static int preg_do_repl_func(zval *function, char *subject, int *offsets, char * /* {{{ preg_do_eval */ -static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, +static zend_str_size_int preg_do_eval(char *eval_str, int eval_str_len, char *subject, int *offsets, int count, char **result TSRMLS_DC) { zval retval; /* Return value from evaluation */ @@ -982,10 +982,10 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject, /* {{{ php_pcre_replace */ -PHPAPI char *php_pcre_replace(char *regex, int regex_len, - char *subject, int subject_len, +PHPAPI char *php_pcre_replace(char *regex, zend_str_size_int regex_len, + char *subject, zend_str_size_int subject_len, zval *replace_val, int is_callable_replace, - int *result_len, int limit, int *replace_count TSRMLS_DC) + zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_cache_entry *pce; /* Compiled regular expression */ @@ -1000,8 +1000,8 @@ PHPAPI char *php_pcre_replace(char *regex, int regex_len, /* }}} */ /* {{{ php_pcre_replace_impl() */ -PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, - int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC) +PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *replace_val, + int is_callable_replace, zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_extra *extra = pce->extra;/* Holds results of studying */ pcre_extra extra_data; /* Used locally for exec options */ @@ -1011,16 +1011,16 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub char **subpat_names; /* Array for named subpatterns */ int num_subpats; /* Number of captured subpatterns */ int size_offsets; /* Size of the offsets array */ - int new_len; /* Length of needed storage */ - int alloc_len; /* Actual allocated length */ - int eval_result_len=0; /* Length of the eval'ed or + zend_str_size_int new_len; /* Length of needed storage */ + zend_str_size_int alloc_len; /* Actual allocated length */ + zend_str_size_int eval_result_len=0; /* Length of the eval'ed or function-returned string */ int match_len; /* Length of the current match */ int backref; /* Backreference number */ int eval; /* If the replacement string should be eval'ed */ int start_offset; /* Where the new search starts */ int g_notempty=0; /* If the match should not be empty */ - int replace_len=0; /* Length of replacement string */ + zend_str_size_int replace_len=0; /* Length of replacement string */ char *result, /* Result of replacement */ *replace=NULL, /* Replacement string */ *new_buf, /* Temporary buffer for re-allocation */ @@ -1243,7 +1243,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub /* {{{ php_replace_in_subject */ -static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, int *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) +static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, zend_str_size_int *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) { zval **regex_entry, **replace_entry = NULL, @@ -1251,7 +1251,7 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, empty_replace; char *subject_value, *result; - int subject_len; + zend_str_size_int subject_len; /* Make sure we're dealing with strings. */ convert_to_string_ex(subject); @@ -1339,7 +1339,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl **subject_entry, **zcount = NULL; char *result; - int result_len; + zend_str_size_int result_len; int limit_val = -1; php_int_t limit = -1; char *string_key; @@ -1472,17 +1472,17 @@ static PHP_FUNCTION(preg_split) } /* Compile regex or get it from cache. */ - if ((pce = pcre_get_compiled_regex_cache(regex, (int) regex_len TSRMLS_CC)) == NULL) { + if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } - php_pcre_split_impl(pce, subject, (int) subject_len, return_value, limit_val, flags TSRMLS_CC); + php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC); } /* }}} */ /* {{{ php_pcre_split */ -PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, +PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, long limit_val, long flags TSRMLS_DC) { pcre_extra *extra = NULL; /* Holds results of studying */ @@ -1753,7 +1753,7 @@ static PHP_FUNCTION(preg_grep) } /* Compile regex or get it from cache. */ - if ((pce = pcre_get_compiled_regex_cache(regex, (int) regex_len TSRMLS_CC)) == NULL) { + if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { RETURN_FALSE; } -- cgit v1.2.1 From de99f93aa5a7791c8ad46945cd9c96a3280f2e78 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 7 Nov 2013 17:47:48 +0100 Subject: fix datatype for hash vars --- ext/pcre/php_pcre.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 09713eb7ad..ddff1793ae 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1343,7 +1343,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl int limit_val = -1; php_int_t limit = -1; char *string_key; - ulong num_key; + zend_uint_t num_key; char *callback_name; int replace_count=0, old_replace_count; @@ -1770,7 +1770,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return int size_offsets; /* Size of the offsets array */ int count = 0; /* Count of matched subpatterns */ char *string_key; - ulong num_key; + zend_uint_t num_key; zend_bool invert; /* Whether to return non-matching entries */ int rc; -- cgit v1.2.1 From c398bdd4a34cc4b5cff38ae1a47d475581480045 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 18 Nov 2013 14:03:55 +0100 Subject: runtime checks for various lengths in pcre --- ext/pcre/php_pcre.c | 61 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index ddff1793ae..46540d876a 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -508,7 +508,7 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr /* }}} */ /* {{{ add_offset_pair */ -static inline void add_offset_pair(zval *result, char *str, zend_str_size_int len, long offset, char *name) +static inline void add_offset_pair(zval *result, char *str, zend_str_size_int len, php_int_t offset, char *name) { zval *match_pair; @@ -557,7 +557,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * /* {{{ php_pcre_match_impl() */ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, - zval *subpats, int global, int use_flags, long flags, long start_offset TSRMLS_DC) + zval *subpats, int global, int use_flags, php_int_t flags, php_int_t start_offset TSRMLS_DC) { zval *result_set, /* Holds a set of subpatterns after a global match */ @@ -578,6 +578,16 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_s int subpats_order; /* Order of subpattern matches */ int offset_capture; /* Capture match offsets: yes/no */ + if (subject_len > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject is too long"); + RETURN_FALSE; + } + + if (start_offset > INT_MAX-1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start offset is too big"); + RETURN_FALSE; + } + /* Overwrite the passed-in value for subpatterns with an empty array. */ if (subpats != NULL) { zval_dtor(subpats); @@ -656,7 +666,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_s do { /* Execute the regular expression. */ - count = pcre_exec(pce->re, extra, subject, subject_len, start_offset, + count = pcre_exec(pce->re, extra, subject, (int)subject_len, (int)start_offset, exoptions|g_notempty, offsets, size_offsets); /* the string was already proved to be valid UTF-8 */ @@ -754,8 +764,8 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_s the start offset, and continue. Fudge the offset values to achieve this, unless we're already at the end of the string. */ if (g_notempty != 0 && start_offset < subject_len) { - offsets[0] = start_offset; - offsets[1] = start_offset + 1; + offsets[0] = (int)start_offset; + offsets[1] = (int)start_offset + 1; } else break; } else { @@ -1033,6 +1043,16 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st walk_last; /* Last walked character */ int rc; + if (subject_len > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject is too long"); + return NULL; + } + + if (Z_STRSIZE_P(replace_val) > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject is too long"); + return NULL; + } + if (extra == NULL) { extra_data.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION; extra = &extra_data; @@ -1088,7 +1108,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st while (1) { /* Execute the regular expression. */ - count = pcre_exec(pce->re, extra, subject, subject_len, start_offset, + count = pcre_exec(pce->re, extra, subject, (int)subject_len, (int)start_offset, exoptions|g_notempty, offsets, size_offsets); /* the string was already proved to be valid UTF-8 */ @@ -1113,7 +1133,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st /* If evaluating, do it and add the return string's length */ if (eval) { - eval_result_len = preg_do_eval(replace, replace_len, subject, + eval_result_len = preg_do_eval(replace, (int)replace_len, subject, offsets, count, &eval_result TSRMLS_CC); new_len += eval_result_len; } else if (is_callable_replace) { @@ -1375,7 +1395,11 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl SEPARATE_ZVAL(subject); if (ZEND_NUM_ARGS() > 3) { - limit_val = limit; + if (limit > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "limit is too big"); + RETURN_FALSE; + } + limit_val = (int)limit; } if (Z_TYPE_PP(regex) != IS_ARRAY) @@ -1483,7 +1507,7 @@ static PHP_FUNCTION(preg_split) /* {{{ php_pcre_split */ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, - long limit_val, long flags TSRMLS_DC) + php_int_t limit_val, php_int_t flags TSRMLS_DC) { pcre_extra *extra = NULL; /* Holds results of studying */ pcre *re_bump = NULL; /* Regex instance for empty matches */ @@ -1502,6 +1526,11 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_s int delim_capture; /* If delimiters should be captured */ int offset_capture; /* If offsets should be captured */ + if (subject_len > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject is too long"); + RETURN_FALSE; + } + no_empty = flags & PREG_SPLIT_NO_EMPTY; delim_capture = flags & PREG_SPLIT_DELIM_CAPTURE; offset_capture = flags & PREG_SPLIT_OFFSET_CAPTURE; @@ -1538,7 +1567,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_s /* Get next piece if no limit or limit not yet reached and something matched*/ while ((limit_val == -1 || limit_val > 1)) { count = pcre_exec(pce->re, extra, subject, - subject_len, start_offset, + (int)subject_len, start_offset, exoptions|g_notempty, offsets, size_offsets); /* the string was already proved to be valid UTF-8 */ @@ -1602,7 +1631,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_s } } count = pcre_exec(re_bump, extra_bump, subject, - subject_len, start_offset, + (int)subject_len, start_offset, exoptions, offsets, size_offsets); if (count < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown error"); @@ -1761,7 +1790,7 @@ static PHP_FUNCTION(preg_grep) } /* }}} */ -PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return_value, long flags TSRMLS_DC) /* {{{ */ +PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return_value, php_int_t flags TSRMLS_DC) /* {{{ */ { zval **entry; /* An entry in the input array */ pcre_extra *extra = pce->extra;/* Holds results of studying */ @@ -1808,9 +1837,15 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return convert_to_string(&subject); } + if (Z_STRSIZE(subject) > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject is too long"); + zend_hash_move_forward(Z_ARRVAL_P(input)); + continue; + } + /* Perform the match */ count = pcre_exec(pce->re, extra, Z_STRVAL(subject), - Z_STRSIZE(subject), 0, + (int)Z_STRSIZE(subject), 0, 0, offsets, size_offsets); /* Check for too many substrings condition. */ -- cgit v1.2.1 From 0cac40e87946b98c6a504d0237f3adb3d32daa4b Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 18 Nov 2013 17:28:48 +0100 Subject: moved the check to the right place and fixed wording --- ext/pcre/php_pcre.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 46540d876a..75454cff84 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1048,11 +1048,6 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st return NULL; } - if (Z_STRSIZE_P(replace_val) > INT_MAX) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Subject is too long"); - return NULL; - } - if (extra == NULL) { extra_data.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION; extra = &extra_data; @@ -1069,6 +1064,10 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st } else { replace = Z_STRVAL_P(replace_val); replace_len = Z_STRSIZE_P(replace_val); + if (replace_len > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Replacement is too long"); + return NULL; + } replace_end = replace + replace_len; } -- cgit v1.2.1 From 4d703a4225977b0c6abb2f88c2fe56732d6452a1 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Dec 2013 12:08:19 +0100 Subject: added range check for pcre ini entries --- ext/pcre/php_pcre.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 3daa8e80e1..05dad381ab 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -114,9 +114,41 @@ static PHP_GSHUTDOWN_FUNCTION(pcre) /* {{{ */ } /* }}} */ +static PHP_INI_MH(OnChangeBacktrackLimit) +{/*{{{*/ + php_int_t i; + + ZEND_ATOI(i, new_value); + + if (i > (unsigned long)-1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value '%pd' is too big for pcre.backtrack_limit", i); + return FAILURE; + } + + PCRE_G(backtrack_limit) = i; + + return SUCCESS; +}/*}}}*/ + +static PHP_INI_MH(OnChangeRecursionLimit) +{/*{{{*/ + php_int_t i; + + ZEND_ATOI(i, new_value); + + if (i > (unsigned long)-1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value '%pd' is too big for pcre.recursion_limit", i); + return FAILURE; + } + + PCRE_G(recursion_limit) = i; + + return SUCCESS; +}/*}}}*/ + PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("pcre.backtrack_limit", "1000000", PHP_INI_ALL, OnUpdateLong, backtrack_limit, zend_pcre_globals, pcre_globals) - STD_PHP_INI_ENTRY("pcre.recursion_limit", "100000", PHP_INI_ALL, OnUpdateLong, recursion_limit, zend_pcre_globals, pcre_globals) + PHP_INI_ENTRY("pcre.backtrack_limit", "1000000", PHP_INI_ALL, OnChangeBacktrackLimit) + PHP_INI_ENTRY("pcre.recursion_limit", "100000", PHP_INI_ALL, OnChangeRecursionLimit) PHP_INI_END() -- cgit v1.2.1 From 122805100a45b396d2849aa61c222851beca5a3e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Dec 2013 12:38:11 +0100 Subject: removed warnings in newly implemented pcre range cehcks --- ext/pcre/php_pcre.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 05dad381ab..1a52216ad7 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -121,7 +121,6 @@ static PHP_INI_MH(OnChangeBacktrackLimit) ZEND_ATOI(i, new_value); if (i > (unsigned long)-1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value '%pd' is too big for pcre.backtrack_limit", i); return FAILURE; } @@ -137,7 +136,6 @@ static PHP_INI_MH(OnChangeRecursionLimit) ZEND_ATOI(i, new_value); if (i > (unsigned long)-1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Value '%pd' is too big for pcre.recursion_limit", i); return FAILURE; } -- cgit v1.2.1 From b1abe4ca21e10b04a8bae2d00e8113f4b2b02567 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 18 Dec 2013 14:46:44 -0800 Subject: mass replacement for zend_size_t/php_size_t --- ext/pcre/php_pcre.c | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 1a52216ad7..2876801e63 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -256,7 +256,7 @@ static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_D /* {{{ pcre_get_compiled_regex_cache */ -PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, zend_str_size_int regex_len TSRMLS_DC) +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, php_size_t regex_len TSRMLS_DC) { pcre *re = NULL; pcre_extra *extra; @@ -538,7 +538,7 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr /* }}} */ /* {{{ add_offset_pair */ -static inline void add_offset_pair(zval *result, char *str, zend_str_size_int len, php_int_t offset, char *name) +static inline void add_offset_pair(zval *result, char *str, php_size_t len, php_int_t offset, char *name) { zval *match_pair; @@ -563,8 +563,8 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * /* parameters */ char *regex; /* Regular expression */ char *subject; /* String to match against */ - zend_str_size regex_len; - zend_str_size subject_len; + php_size_t regex_len; + php_size_t subject_len; pcre_cache_entry *pce; /* Compiled regular expression */ zval *subpats = NULL; /* Array for subpatterns */ php_int_t flags = 0; /* Match control flags */ @@ -586,7 +586,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * /* }}} */ /* {{{ php_pcre_match_impl() */ -PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, +PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, php_size_t subject_len, zval *return_value, zval *subpats, int global, int use_flags, php_int_t flags, php_int_t start_offset TSRMLS_DC) { zval *result_set, /* Holds a set of subpatterns after @@ -895,12 +895,12 @@ static int preg_get_backref(char **str, int *backref) /* {{{ preg_do_repl_func */ -static zend_str_size_int preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) +static php_size_t preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC) { zval *retval_ptr; /* Function return value */ zval **args[1]; /* Argument to pass to function */ zval *subpats; /* Captured subpatterns */ - zend_str_size_int result_len; /* Return value length */ + php_size_t result_len; /* Return value length */ int i; MAKE_STD_ZVAL(subpats); @@ -934,7 +934,7 @@ static zend_str_size_int preg_do_repl_func(zval *function, char *subject, int *o /* {{{ preg_do_eval */ -static zend_str_size_int preg_do_eval(char *eval_str, int eval_str_len, char *subject, +static php_size_t preg_do_eval(char *eval_str, int eval_str_len, char *subject, int *offsets, int count, char **result TSRMLS_DC) { zval retval; /* Return value from evaluation */ @@ -944,9 +944,9 @@ static zend_str_size_int preg_do_eval(char *eval_str, int eval_str_len, char *su *walk, /* Used to walk the code string */ *segment, /* Start of segment to append while walking */ walk_last; /* Last walked character */ - zend_str_size match_len; /* Length of the match */ - zend_str_size esc_match_len; /* Length of the quote-escaped match */ - zend_str_size result_len; /* Length of the result of the evaluation */ + php_size_t match_len; /* Length of the match */ + php_size_t esc_match_len; /* Length of the quote-escaped match */ + php_size_t result_len; /* Length of the result of the evaluation */ int backref; /* Current backref */ char *compiled_string_description; smart_str code = {0}; @@ -1022,10 +1022,10 @@ static zend_str_size_int preg_do_eval(char *eval_str, int eval_str_len, char *su /* {{{ php_pcre_replace */ -PHPAPI char *php_pcre_replace(char *regex, zend_str_size_int regex_len, - char *subject, zend_str_size_int subject_len, +PHPAPI char *php_pcre_replace(char *regex, php_size_t regex_len, + char *subject, php_size_t subject_len, zval *replace_val, int is_callable_replace, - zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) + php_size_t *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_cache_entry *pce; /* Compiled regular expression */ @@ -1040,8 +1040,8 @@ PHPAPI char *php_pcre_replace(char *regex, zend_str_size_int regex_len, /* }}} */ /* {{{ php_pcre_replace_impl() */ -PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *replace_val, - int is_callable_replace, zend_str_size_int *result_len, int limit, int *replace_count TSRMLS_DC) +PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, php_size_t subject_len, zval *replace_val, + int is_callable_replace, php_size_t *result_len, int limit, int *replace_count TSRMLS_DC) { pcre_extra *extra = pce->extra;/* Holds results of studying */ pcre_extra extra_data; /* Used locally for exec options */ @@ -1051,16 +1051,16 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st char **subpat_names; /* Array for named subpatterns */ int num_subpats; /* Number of captured subpatterns */ int size_offsets; /* Size of the offsets array */ - zend_str_size_int new_len; /* Length of needed storage */ - zend_str_size_int alloc_len; /* Actual allocated length */ - zend_str_size_int eval_result_len=0; /* Length of the eval'ed or + php_size_t new_len; /* Length of needed storage */ + php_size_t alloc_len; /* Actual allocated length */ + php_size_t eval_result_len=0; /* Length of the eval'ed or function-returned string */ int match_len; /* Length of the current match */ int backref; /* Backreference number */ int eval; /* If the replacement string should be eval'ed */ int start_offset; /* Where the new search starts */ int g_notempty=0; /* If the match should not be empty */ - zend_str_size_int replace_len=0; /* Length of replacement string */ + php_size_t replace_len=0; /* Length of replacement string */ char *result, /* Result of replacement */ *replace=NULL, /* Replacement string */ *new_buf, /* Temporary buffer for re-allocation */ @@ -1292,7 +1292,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, zend_st /* {{{ php_replace_in_subject */ -static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, zend_str_size_int *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) +static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, php_size_t *result_len, int limit, int is_callable_replace, int *replace_count TSRMLS_DC) { zval **regex_entry, **replace_entry = NULL, @@ -1300,7 +1300,7 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, empty_replace; char *subject_value, *result; - zend_str_size_int subject_len; + php_size_t subject_len; /* Make sure we're dealing with strings. */ convert_to_string_ex(subject); @@ -1388,11 +1388,11 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl **subject_entry, **zcount = NULL; char *result; - zend_str_size_int result_len; + php_size_t result_len; int limit_val = -1; php_int_t limit = -1; char *string_key; - zend_str_size_uint string_key_len; + php_size_t string_key_len; php_uint_t num_key; char *callback_name; int replace_count=0, old_replace_count; @@ -1455,7 +1455,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl break; case HASH_KEY_IS_LONG: - add_index_stringl(return_value, num_key, result, (zend_str_size) result_len, 0); + add_index_stringl(return_value, num_key, result, (php_size_t) result_len, 0); break; } } else { @@ -1469,7 +1469,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl old_replace_count = replace_count; if ((result = php_replace_in_subject(*regex, *replace, subject, &result_len, limit_val, is_callable_replace, &replace_count TSRMLS_CC)) != NULL) { if (!is_filter || replace_count > old_replace_count) { - RETVAL_STRINGL(result, (zend_str_size) result_len, 0); + RETVAL_STRINGL(result, (php_size_t) result_len, 0); } else { efree(result); } @@ -1513,8 +1513,8 @@ static PHP_FUNCTION(preg_split) { char *regex; /* Regular expression */ char *subject; /* String to match against */ - zend_str_size regex_len; - zend_str_size subject_len; + php_size_t regex_len; + php_size_t subject_len; php_int_t limit_val = -1;/* Integer value of limit */ php_int_t flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ @@ -1536,7 +1536,7 @@ static PHP_FUNCTION(preg_split) /* {{{ php_pcre_split */ -PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_size_int subject_len, zval *return_value, +PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, php_size_t subject_len, zval *return_value, php_int_t limit_val, php_int_t flags TSRMLS_DC) { pcre_extra *extra = NULL; /* Holds results of studying */ @@ -1712,10 +1712,10 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, zend_str_s Quote regular expression characters plus an optional character */ static PHP_FUNCTION(preg_quote) { - zend_str_size in_str_len; + php_size_t in_str_len; char *in_str; /* Input string argument */ char *in_str_end; /* End of the input string */ - zend_str_size delim_len = 0; + php_size_t delim_len = 0; char *delim = NULL; /* Additional delimiter argument */ char *out_str, /* Output string with quoted characters */ *p, /* Iterator for input string */ @@ -1800,7 +1800,7 @@ static PHP_FUNCTION(preg_quote) static PHP_FUNCTION(preg_grep) { char *regex; /* Regular expression */ - zend_str_size regex_len; + php_size_t regex_len; zval *input; /* Input array */ php_int_t flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ @@ -1829,7 +1829,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return int size_offsets; /* Size of the offsets array */ int count = 0; /* Count of matched subpatterns */ char *string_key; - zend_str_size_uint string_key_len; + php_size_t string_key_len; php_uint_t num_key; zend_bool invert; /* Whether to return non-matching entries */ -- cgit v1.2.1 From f58d0b35edf25a8f39fad6bd5e0e4eeb5cdfe9a7 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 19 Dec 2013 05:07:37 -0800 Subject: massive update semantical LONG vs INT replacements --- ext/pcre/php_pcre.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 2876801e63..416a142445 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -167,20 +167,20 @@ static PHP_MINIT_FUNCTION(pcre) { REGISTER_INI_ENTRIES(); - REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("PCRE_VERSION", (char *)pcre_version(), CONST_CS | CONST_PERSISTENT); return SUCCESS; @@ -831,7 +831,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, php_size_t /* Did we encounter an error? */ if (PCRE_G(error_code) == PHP_PCRE_NO_ERROR) { - RETVAL_LONG(matched); + RETVAL_INT(matched); } else { RETVAL_FALSE; } @@ -1454,7 +1454,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl add_assoc_stringl_ex(return_value, string_key, string_key_len, result, result_len, 0); break; - case HASH_KEY_IS_LONG: + case HASH_KEY_IS_INT: add_index_stringl(return_value, num_key, result, (php_size_t) result_len, 0); break; } @@ -1477,7 +1477,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl } if (ZEND_NUM_ARGS() > 4) { zval_dtor(*zcount); - ZVAL_LONG(*zcount, replace_count); + ZVAL_INT(*zcount, replace_count); } } @@ -1901,7 +1901,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return string_key_len, entry, sizeof(zval *), NULL); break; - case HASH_KEY_IS_LONG: + case HASH_KEY_IS_INT: zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry, sizeof(zval *), NULL); break; @@ -1928,7 +1928,7 @@ static PHP_FUNCTION(preg_last_error) return; } - RETURN_LONG(PCRE_G(error_code)); + RETURN_INT(PCRE_G(error_code)); } /* }}} */ -- cgit v1.2.1 From 6125278290aa3ab2ac0a1ad22116b9d363b3e915 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 19 Dec 2013 08:40:41 -0800 Subject: more semantical replacements LONG vs. INT --- ext/pcre/php_pcre.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 416a142445..1e631f2e31 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -548,7 +548,7 @@ static inline void add_offset_pair(zval *result, char *str, php_size_t len, php_ /* Add (match, offset) to the return value */ add_next_index_stringl(match_pair, str, len, 1); - add_next_index_long(match_pair, offset); + add_next_index_int(match_pair, offset); if (name) { zval_add_ref(&match_pair); -- cgit v1.2.1 From cb25136f4ef1042295650475b2c20ace81e2b9b7 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 11:37:14 +0200 Subject: fix macros in the 5 basic extensions --- ext/pcre/php_pcre.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 4731db21fb..ddfccc3763 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -143,20 +143,20 @@ static PHP_MINIT_FUNCTION(pcre) { REGISTER_INI_ENTRIES(); - REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_INT_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("PCRE_VERSION", (char *)pcre_version(), CONST_CS | CONST_PERSISTENT); return SUCCESS; @@ -527,7 +527,7 @@ static inline void add_offset_pair(zval *result, char *str, int len, int offset, /* Add (match, offset) to the return value */ add_next_index_stringl(&match_pair, str, len); - add_next_index_long(&match_pair, offset); + add_next_index_int(&match_pair, offset); if (name) { zval_add_ref(&match_pair); @@ -888,7 +888,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec /* Did we encounter an error? */ if (PCRE_G(error_code) == PHP_PCRE_NO_ERROR) { - RETVAL_LONG(matched); + RETVAL_INT(matched); } else { RETVAL_FALSE; } @@ -1142,7 +1142,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, } } else { replace = Z_STRVAL_P(replace_val); - replace_len = Z_STRLEN_P(replace_val); + replace_len = Z_STRSIZE_P(replace_val); replace_end = replace + replace_len; } @@ -1519,7 +1519,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl } if (ZEND_NUM_ARGS() > 4) { zval_dtor(zcount); - ZVAL_LONG(zcount, replace_count); + ZVAL_INT(zcount, replace_count); } } @@ -1988,7 +1988,7 @@ static PHP_FUNCTION(preg_last_error) ZEND_PARSE_PARAMETERS_END(); #endif - RETURN_LONG(PCRE_G(error_code)); + RETURN_INT(PCRE_G(error_code)); } /* }}} */ -- cgit v1.2.1 From b7e7a895414bd1821686932d57949f1ad0693900 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 12:55:13 +0200 Subject: several fixes - - param parsing Z_PARAM_STR vs Z_PARAM_STRING - some functions for new params - etc --- ext/pcre/php_pcre.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index ddfccc3763..bc878d0c31 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -541,22 +541,21 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * { /* parameters */ zend_string *regex; /* Regular expression */ - char *subject; /* String to match against */ - int subject_len; + zend_string *subject; /* String to match against */ pcre_cache_entry *pce; /* Compiled regular expression */ zval *subpats = NULL; /* Array for subpatterns */ long flags = 0; /* Match control flags */ long start_offset = 0; /* Where the new search starts */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ss|z/ll", ®ex, - &subject, &subject_len, &subpats, &flags, &start_offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z/ll", ®ex, + &subject, &subpats, &flags, &start_offset) == FAILURE) { RETURN_FALSE; } #else ZEND_PARSE_PARAMETERS_START(2, 5) Z_PARAM_STR(regex) - Z_PARAM_STRING(subject, subject_len) + Z_PARAM_STR(subject) Z_PARAM_OPTIONAL Z_PARAM_ZVAL_EX(subpats, 0, 1) Z_PARAM_LONG(flags) @@ -569,7 +568,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * RETURN_FALSE; } - php_pcre_match_impl(pce, subject, subject_len, return_value, subpats, + php_pcre_match_impl(pce, subject->val, subject->len, return_value, subpats, global, ZEND_NUM_ARGS() >= 4, flags, start_offset TSRMLS_CC); } /* }}} */ @@ -1554,22 +1553,21 @@ static PHP_FUNCTION(preg_filter) static PHP_FUNCTION(preg_split) { zend_string *regex; /* Regular expression */ - char *subject; /* String to match against */ - int subject_len; + zend_string *subject; /* String to match against */ long limit_val = -1;/* Integer value of limit */ long flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get function parameters and do error checking */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ss|ll", ®ex, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ll", ®ex, &subject, &subject_len, &limit_val, &flags) == FAILURE) { RETURN_FALSE; } #else ZEND_PARSE_PARAMETERS_START(2, 4) Z_PARAM_STR(regex) - Z_PARAM_STRING(subject, subject_len) + Z_PARAM_STR(subject) Z_PARAM_OPTIONAL Z_PARAM_LONG(limit_val) Z_PARAM_LONG(flags) @@ -1581,7 +1579,7 @@ static PHP_FUNCTION(preg_split) RETURN_FALSE; } - php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC); + php_pcre_split_impl(pce, subject->val, subject->len, return_value, limit_val, flags TSRMLS_CC); } /* }}} */ -- cgit v1.2.1 From 1169de3e61975fe00fbf4768318eb095f22c63ec Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 14:00:02 +0200 Subject: fix some cases with fast zpp --- ext/pcre/php_pcre.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index bc878d0c31..3ff51978c9 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -544,11 +544,11 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * zend_string *subject; /* String to match against */ pcre_cache_entry *pce; /* Compiled regular expression */ zval *subpats = NULL; /* Array for subpatterns */ - long flags = 0; /* Match control flags */ - long start_offset = 0; /* Where the new search starts */ + php_int_t flags = 0; /* Match control flags */ + php_int_t start_offset = 0; /* Where the new search starts */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z/ll", ®ex, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z/ii", ®ex, &subject, &subpats, &flags, &start_offset) == FAILURE) { RETURN_FALSE; } @@ -1434,7 +1434,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl *subject_entry, *zcount = NULL; int limit_val = -1; - long limit = -1; + php_int_t limit = -1; zend_string *result; zend_string *string_key; ulong num_key; @@ -1443,7 +1443,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl #ifndef FAST_ZPP /* Get function parameters and do error-checking. */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|lz/", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|iz/", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { return; } #else @@ -1553,14 +1553,14 @@ static PHP_FUNCTION(preg_filter) static PHP_FUNCTION(preg_split) { zend_string *regex; /* Regular expression */ - zend_string *subject; /* String to match against */ - long limit_val = -1;/* Integer value of limit */ - long flags = 0; /* Match control flags */ + zend_string *subject; /* String to match against */ + php_int_t limit_val = -1;/* Integer value of limit */ + php_int_t flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get function parameters and do error checking */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ll", ®ex, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ii", ®ex, &subject, &subject_len, &limit_val, &flags) == FAILURE) { RETURN_FALSE; } @@ -1862,12 +1862,12 @@ static PHP_FUNCTION(preg_grep) { zend_string *regex; /* Regular expression */ zval *input; /* Input array */ - long flags = 0; /* Match control flags */ + php_int_t flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get arguments and do error checking */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sa|l", ®ex, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sa|i", ®ex, &input, &flags) == FAILURE) { return; } -- cgit v1.2.1 From 90d6f60bc17bb4fea69feeab506eb02bfeec20fd Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 17 Aug 2014 13:31:39 +0200 Subject: mostly fixes to spl, but also some other --- ext/pcre/php_pcre.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 3ff51978c9..3990580640 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1437,10 +1437,10 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl php_int_t limit = -1; zend_string *result; zend_string *string_key; - ulong num_key; + php_uint_t num_key; zend_string *callback_name; int replace_count=0, old_replace_count; - + #ifndef FAST_ZPP /* Get function parameters and do error-checking. */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|iz/", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { @@ -1898,7 +1898,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return int size_offsets; /* Size of the offsets array */ int count = 0; /* Count of matched subpatterns */ zend_string *string_key; - ulong num_key; + php_uint_t num_key; zend_bool invert; /* Whether to return non-matching entries */ ALLOCA_FLAG(use_heap); -- cgit v1.2.1 From f2182ab845236a112ff63bcb8752b07943c999f1 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 17 Aug 2014 21:16:27 +0200 Subject: some more pure naming replacements --- ext/pcre/php_pcre.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 3990580640..d7c7c56a93 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -558,8 +558,8 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * Z_PARAM_STR(subject) Z_PARAM_OPTIONAL Z_PARAM_ZVAL_EX(subpats, 0, 1) - Z_PARAM_LONG(flags) - Z_PARAM_LONG(start_offset) + Z_PARAM_INT(flags) + Z_PARAM_INT(start_offset) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif @@ -1452,7 +1452,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl Z_PARAM_ZVAL(replace) Z_PARAM_ZVAL(subject) Z_PARAM_OPTIONAL - Z_PARAM_LONG(limit) + Z_PARAM_INT(limit) Z_PARAM_ZVAL_EX(zcount, 0, 1) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1569,8 +1569,8 @@ static PHP_FUNCTION(preg_split) Z_PARAM_STR(regex) Z_PARAM_STR(subject) Z_PARAM_OPTIONAL - Z_PARAM_LONG(limit_val) - Z_PARAM_LONG(flags) + Z_PARAM_INT(limit_val) + Z_PARAM_INT(flags) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif @@ -1876,7 +1876,7 @@ static PHP_FUNCTION(preg_grep) Z_PARAM_STR(regex) Z_PARAM_ARRAY(input) Z_PARAM_OPTIONAL - Z_PARAM_LONG(flags) + Z_PARAM_INT(flags) ZEND_PARSE_PARAMETERS_END(); #endif -- cgit v1.2.1 From c3e3c98ec666812daaaca896cf5ef758a8a6df14 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 19:24:55 +0200 Subject: master renames phase 1 --- ext/pcre/php_pcre.c | 120 ++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index d7c7c56a93..6aec12e9b1 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -143,20 +143,20 @@ static PHP_MINIT_FUNCTION(pcre) { REGISTER_INI_ENTRIES(); - REGISTER_INT_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT); - - REGISTER_INT_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT); - REGISTER_INT_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("PCRE_VERSION", (char *)pcre_version(), CONST_CS | CONST_PERSISTENT); return SUCCESS; @@ -527,7 +527,7 @@ static inline void add_offset_pair(zval *result, char *str, int len, int offset, /* Add (match, offset) to the return value */ add_next_index_stringl(&match_pair, str, len); - add_next_index_int(&match_pair, offset); + add_next_index_long(&match_pair, offset); if (name) { zval_add_ref(&match_pair); @@ -544,11 +544,11 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * zend_string *subject; /* String to match against */ pcre_cache_entry *pce; /* Compiled regular expression */ zval *subpats = NULL; /* Array for subpatterns */ - php_int_t flags = 0; /* Match control flags */ - php_int_t start_offset = 0; /* Where the new search starts */ + zend_long flags = 0; /* Match control flags */ + zend_long start_offset = 0; /* Where the new search starts */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z/ii", ®ex, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z/ll", ®ex, &subject, &subpats, &flags, &start_offset) == FAILURE) { RETURN_FALSE; } @@ -558,8 +558,8 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ * Z_PARAM_STR(subject) Z_PARAM_OPTIONAL Z_PARAM_ZVAL_EX(subpats, 0, 1) - Z_PARAM_INT(flags) - Z_PARAM_INT(start_offset) + Z_PARAM_LONG(flags) + Z_PARAM_LONG(start_offset) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif @@ -887,7 +887,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec /* Did we encounter an error? */ if (PCRE_G(error_code) == PHP_PCRE_NO_ERROR) { - RETVAL_INT(matched); + RETVAL_LONG(matched); } else { RETVAL_FALSE; } @@ -983,7 +983,7 @@ static zend_string *preg_do_repl_func(zval *function, char *subject, int *offset php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call custom replacement function"); } - result_str = STR_INIT(&subject[offsets[0]], offsets[1] - offsets[0], 0); + result_str = zend_string_init(&subject[offsets[0]], offsets[1] - offsets[0], 0); } zval_ptr_dtor(&args[0]); @@ -1034,7 +1034,7 @@ static zend_string *preg_do_eval(char *eval_str, int eval_str_len, char *subject if (match_len) { esc_match = php_addslashes(match, match_len, 0 TSRMLS_CC); } else { - esc_match = STR_INIT(match, match_len, 0); + esc_match = zend_string_init(match, match_len, 0); } } else { esc_match = STR_EMPTY_ALLOC(); @@ -1044,7 +1044,7 @@ static zend_string *preg_do_eval(char *eval_str, int eval_str_len, char *subject segment = walk; /* Clean up and reassign */ - STR_RELEASE(esc_match); + zend_string_release(esc_match); continue; } } @@ -1141,7 +1141,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, } } else { replace = Z_STRVAL_P(replace_val); - replace_len = Z_STRSIZE_P(replace_val); + replace_len = Z_STRLEN_P(replace_val); replace_end = replace + replace_len; } @@ -1171,7 +1171,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, } alloc_len = 2 * subject_len; - result = STR_ALLOC(alloc_len * sizeof(char), 0); + result = zend_string_alloc(alloc_len * sizeof(char), 0); /* Initialize */ match = NULL; @@ -1241,7 +1241,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, if (new_len > alloc_len) { alloc_len = alloc_len + 2 * new_len; - result = STR_REALLOC(result, alloc_len, 0); + result = zend_string_realloc(result, alloc_len, 0); } /* copy the part of the string before the match */ memcpy(&result->val[result_len], piece, match-piece); @@ -1255,7 +1255,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, if (eval || is_callable_replace) { memcpy(walkbuf, eval_result->val, eval_result->len); result_len += eval_result->len; - if (eval_result) STR_RELEASE(eval_result); + if (eval_result) zend_string_release(eval_result); } else { /* do regular backreference copying */ walk = replace; walk_last = 0; @@ -1300,7 +1300,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, new_len = result_len + subject_len - start_offset; if (new_len > alloc_len) { alloc_len = new_len; /* now we know exactly how long it is */ - result = STR_REALLOC(result, alloc_len, 0); + result = zend_string_realloc(result, alloc_len, 0); } /* stick that last bit of string on our output */ memcpy(&result->val[result_len], piece, subject_len - start_offset); @@ -1310,7 +1310,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, } } else { pcre_handle_exec_error(count TSRMLS_CC); - STR_FREE(result); + zend_string_free(result); result = NULL; break; } @@ -1398,15 +1398,15 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub is_callable_replace, limit, replace_count TSRMLS_CC)) != NULL) { - STR_RELEASE(subject_str); + zend_string_release(subject_str); subject_str = result; } else { - STR_RELEASE(subject_str); - STR_RELEASE(regex_str); + zend_string_release(subject_str); + zend_string_release(regex_str); return NULL; } - STR_RELEASE(regex_str); + zend_string_release(regex_str); } ZEND_HASH_FOREACH_END(); return subject_str; @@ -1418,7 +1418,7 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub is_callable_replace, limit, replace_count TSRMLS_CC); - STR_RELEASE(subject_str); + zend_string_release(subject_str); return result; } } @@ -1434,16 +1434,16 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl *subject_entry, *zcount = NULL; int limit_val = -1; - php_int_t limit = -1; + zend_long limit = -1; zend_string *result; zend_string *string_key; - php_uint_t num_key; + zend_ulong num_key; zend_string *callback_name; int replace_count=0, old_replace_count; #ifndef FAST_ZPP /* Get function parameters and do error-checking. */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|iz/", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|lz/", ®ex, &replace, &subject, &limit, &zcount) == FAILURE) { return; } #else @@ -1452,7 +1452,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl Z_PARAM_ZVAL(replace) Z_PARAM_ZVAL(subject) Z_PARAM_OPTIONAL - Z_PARAM_INT(limit) + Z_PARAM_LONG(limit) Z_PARAM_ZVAL_EX(zcount, 0, 1) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1469,11 +1469,11 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl if (is_callable_replace) { if (!zend_is_callable(replace, 0, &callback_name TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires argument 2, '%s', to be a valid callback", callback_name->val); - STR_RELEASE(callback_name); + zend_string_release(callback_name); ZVAL_DUP(return_value, subject); return; } - STR_RELEASE(callback_name); + zend_string_release(callback_name); } if (ZEND_NUM_ARGS() > 3) { @@ -1502,7 +1502,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl add_index_str(return_value, num_key, result); } } else { - STR_RELEASE(result); + zend_string_release(result); } } } ZEND_HASH_FOREACH_END(); @@ -1512,13 +1512,13 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl if (!is_filter || replace_count > old_replace_count) { RETVAL_STR(result); } else { - STR_RELEASE(result); + zend_string_release(result); } } } if (ZEND_NUM_ARGS() > 4) { zval_dtor(zcount); - ZVAL_INT(zcount, replace_count); + ZVAL_LONG(zcount, replace_count); } } @@ -1554,13 +1554,13 @@ static PHP_FUNCTION(preg_split) { zend_string *regex; /* Regular expression */ zend_string *subject; /* String to match against */ - php_int_t limit_val = -1;/* Integer value of limit */ - php_int_t flags = 0; /* Match control flags */ + zend_long limit_val = -1;/* Integer value of limit */ + zend_long flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get function parameters and do error checking */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ii", ®ex, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ll", ®ex, &subject, &subject_len, &limit_val, &flags) == FAILURE) { RETURN_FALSE; } @@ -1569,8 +1569,8 @@ static PHP_FUNCTION(preg_split) Z_PARAM_STR(regex) Z_PARAM_STR(subject) Z_PARAM_OPTIONAL - Z_PARAM_INT(limit_val) - Z_PARAM_INT(flags) + Z_PARAM_LONG(limit_val) + Z_PARAM_LONG(flags) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); #endif @@ -1701,9 +1701,9 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec if (pce->compile_options & PCRE_UTF8) { if (re_bump == NULL) { int dummy; - zend_string *regex = STR_INIT("/./us", sizeof("/./us")-1, 0); + zend_string *regex = zend_string_init("/./us", sizeof("/./us")-1, 0); re_bump = pcre_get_compiled_regex(regex, &extra_bump, &dummy TSRMLS_CC); - STR_RELEASE(regex); + zend_string_release(regex); if (re_bump == NULL) { RETURN_FALSE; } @@ -1804,7 +1804,7 @@ static PHP_FUNCTION(preg_quote) /* Allocate enough memory so that even if each character is quoted, we won't run out of room */ - out_str = STR_SAFE_ALLOC(4, in_str_len, 0, 0); + out_str = zend_string_safe_alloc(4, in_str_len, 0, 0); /* Go through the string and quote necessary characters */ for (p = in_str, q = out_str->val; p != in_str_end; p++) { @@ -1851,7 +1851,7 @@ static PHP_FUNCTION(preg_quote) *q = '\0'; /* Reallocate string and return it */ - out_str = STR_REALLOC(out_str, q - out_str->val, 0); + out_str = zend_string_realloc(out_str, q - out_str->val, 0); RETURN_STR(out_str); } /* }}} */ @@ -1862,12 +1862,12 @@ static PHP_FUNCTION(preg_grep) { zend_string *regex; /* Regular expression */ zval *input; /* Input array */ - php_int_t flags = 0; /* Match control flags */ + zend_long flags = 0; /* Match control flags */ pcre_cache_entry *pce; /* Compiled regular expression */ /* Get arguments and do error checking */ #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sa|i", ®ex, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sa|l", ®ex, &input, &flags) == FAILURE) { return; } @@ -1876,7 +1876,7 @@ static PHP_FUNCTION(preg_grep) Z_PARAM_STR(regex) Z_PARAM_ARRAY(input) Z_PARAM_OPTIONAL - Z_PARAM_INT(flags) + Z_PARAM_LONG(flags) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1898,7 +1898,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return int size_offsets; /* Size of the offsets array */ int count = 0; /* Count of matched subpatterns */ zend_string *string_key; - php_uint_t num_key; + zend_ulong num_key; zend_bool invert; /* Whether to return non-matching entries */ ALLOCA_FLAG(use_heap); @@ -1943,7 +1943,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return count = size_offsets/3; } else if (count < 0 && count != PCRE_ERROR_NOMATCH) { pcre_handle_exec_error(count TSRMLS_CC); - STR_RELEASE(subject_str); + zend_string_release(subject_str); break; } @@ -1961,7 +1961,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return } } - STR_RELEASE(subject_str); + zend_string_release(subject_str); } ZEND_HASH_FOREACH_END(); /* Clean up */ @@ -1986,7 +1986,7 @@ static PHP_FUNCTION(preg_last_error) ZEND_PARSE_PARAMETERS_END(); #endif - RETURN_INT(PCRE_G(error_code)); + RETURN_LONG(PCRE_G(error_code)); } /* }}} */ -- cgit v1.2.1 From 6f9f0bf2056f0dc17d9bcc6dd3b7d28ac878c6fc Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 19:28:33 +0200 Subject: master renames phase 2 --- ext/pcre/php_pcre.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 6aec12e9b1..9be65164cd 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1351,7 +1351,7 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub empty_replace; zend_string *result; zend_string *subject_str = zval_get_string(subject); - zend_uint replace_idx; + uint32_t replace_idx; /* FIXME: This might need to be changed to STR_EMPTY_ALLOC(). Check if this zval could be dtor()'ed somehow */ ZVAL_EMPTY_STRING(&empty_replace); -- cgit v1.2.1 From 3234480827b27ff5d3469a732167afd289632a96 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 27 Aug 2014 15:31:48 +0200 Subject: first show to make 's' work with size_t --- ext/pcre/php_pcre.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/pcre/php_pcre.c') diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 9be65164cd..89c5f1155b 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1764,10 +1764,10 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subjec Quote regular expression characters plus an optional character */ static PHP_FUNCTION(preg_quote) { - int in_str_len; + size_t in_str_len; char *in_str; /* Input string argument */ char *in_str_end; /* End of the input string */ - int delim_len = 0; + size_t delim_len = 0; char *delim = NULL; /* Additional delimiter argument */ zend_string *out_str; /* Output string with quoted characters */ char *p, /* Iterator for input string */ -- cgit v1.2.1