]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
With the changes of api from pcre 8.x to 10.x, do not presume that the internal
authorWilliam A. Rowe Jr <wrowe@apache.org>
Mon, 12 Dec 2016 21:57:06 +0000 (21:57 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Mon, 12 Dec 2016 21:57:06 +0000 (21:57 +0000)
ovector will be created to accept greater than nmatch elements for processing.
Allocate enough elts in all circumstances for pcre2api.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1773882 13f79535-47bb-0310-9956-ffa450edef68

server/util_pcre.c

index 9c83e203a75c955696f2062d3780551f7be451c5..40dbf0787fd7e6ac7f3a64c639ec9c640ac9400b 100644 (file)
@@ -232,6 +232,7 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
 {
     int rc;
     int options = 0;
+    apr_size_t nlim;
 #ifdef HAVE_PCRE2
     pcre2_match_data *matchdata;
     size_t *ovector;
@@ -251,13 +252,17 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
      * e.g. 10 matches, to avoid a malloc-per-call. If it must be alloced,
      * implement a general context using palloc and no free implementation.
      */
-    matchdata = pcre2_match_data_create(nmatch, NULL);
+    nlim = ((apr_size_t)preg->re_nsub + 1) > nmatch
+         ? ((apr_size_t)preg->re_nsub + 1) : nmatch;
+    matchdata = pcre2_match_data_create(nlim, NULL);
     if (matchdata == NULL)
         return AP_REG_ESPACE;
     ovector = pcre2_get_ovector_pointer(matchdata);
     rc = pcre2_match((const pcre2_code *)preg->re_pcre,
                      (const unsigned char *)buff, len,
                      0, options, matchdata, NULL);
+    if (rc == 0)
+        rc = nlim;            /* All captured slots were filled in */
 #else
     if (nmatch > 0) {
         if (nmatch <= POSIX_MALLOC_THRESHOLD) {
@@ -272,14 +277,13 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
     }
     rc = pcre_exec((const pcre *)preg->re_pcre, NULL, buff, (int)len,
                    0, options, ovector, nmatch * 3);
-#endif
-
     if (rc == 0)
         rc = nmatch;            /* All captured slots were filled in */
+#endif
 
     if (rc >= 0) {
         apr_size_t i;
-        apr_size_t nlim = (apr_size_t)rc < nmatch ? (apr_size_t)rc : nmatch;
+        nlim = (apr_size_t)rc < nmatch ? (apr_size_t)rc : nmatch;
         for (i = 0; i < nlim; i++) {
             pmatch[i].rm_so = ovector[i * 2];
             pmatch[i].rm_eo = ovector[i * 2 + 1];