diff options
author | Anatol Belski <ab@php.net> | 2017-10-12 12:48:36 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2017-11-13 19:37:38 +0100 |
commit | a5bc5aed71f7a15f14f33bb31b8e17bf5f327e2d (patch) | |
tree | fe551e3a9eb951119e0b795f180e11e47a3f4c21 /ext/zip | |
parent | fd463cfbad66c962d25647211602c69303369206 (diff) | |
download | php-git-a5bc5aed71f7a15f14f33bb31b8e17bf5f327e2d.tar.gz |
Patch core for PCRE2 support
RFC https://wiki.php.net/rfc/pcre2-migration
Diffstat (limited to 'ext/zip')
-rw-r--r-- | ext/zip/php_zip.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index b5df2481e5..5bea9d934c 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -625,6 +625,7 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val #endif int files_cnt; zend_string **namelist; + pcre2_match_context *mctx = php_pcre_mctx(); #ifdef ZTS if (!IS_ABSOLUTE_PATH(path, path_len)) { @@ -651,11 +652,12 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val files_cnt = php_stream_scandir(path, &namelist, NULL, (void *) php_stream_dirent_alphasort); if (files_cnt > 0) { - pcre *re = NULL; - pcre_extra *pcre_extra = NULL; - int preg_options = 0, i; + pcre2_code *re = NULL; + pcre2_match_data *match_data = NULL; + uint32_t preg_options = 0, i, capture_count; + int rc; - re = pcre_get_compiled_regex(regexp, &pcre_extra, &preg_options); + re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options); if (!re) { php_error_docref(NULL, E_WARNING, "Invalid expression"); return -1; @@ -667,9 +669,7 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val for (i = 0; i < files_cnt; i++) { zend_stat_t s; char fullpath[MAXPATHLEN]; - int ovector[3]; - int matches; - int namelist_len = ZSTR_LEN(namelist[i]); + size_t namelist_len = ZSTR_LEN(namelist[i]); if ((namelist_len == 1 && ZSTR_VAL(namelist[i])[0] == '.') || (namelist_len == 2 && ZSTR_VAL(namelist[i])[0] == '.' && ZSTR_VAL(namelist[i])[1] == '.')) { @@ -697,9 +697,16 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val continue; } - matches = pcre_exec(re, NULL, ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, 0, ovector, 3); + match_data = php_pcre_create_match_data(capture_count, re); + if (!match_data) { + /* Allocation failed, but can proceed to the next pattern. */ + zend_string_release(namelist[i]); + continue; + } + rc = pcre2_match(re, ZSTR_VAL(namelist[i]), ZSTR_LEN(namelist[i]), 0, preg_options, match_data, mctx); + php_pcre_free_match_data(match_data); /* 0 means that the vector is too small to hold all the captured substring offsets */ - if (matches < 0) { + if (rc < 0) { zend_string_release(namelist[i]); continue; } |