On Thu, Dec 08, 2016 at 11:09:42AM -0600, William A Rowe Jr wrote:
> I've beaten my head against this wall for a bit longer, and came up with
> several places where pcre2 changed return types for void *what query
> interogations (especially from int to uint32, badness on x86_64-linux).
> 
> The attached patch picks up these bad void * type assignments. Still
> no tremendous improvement, missing something blatantly obvious,
> I expect.
> 
After few hours of getting httpd sources and tests and hacking them to
actually obtain a pass, I applied your patch and looked what's wrong with your
PCRE2 code.

The t/apache/expr.t failed because the pcre2_match() alwayes returned -51
that means PCRE2_ERROR_NULL. The reason is you used the old PCRE optimization
path and called pcre2_match_data_create(nmatch, NULL) only if nmatch was
positive. As a result, pcre2_match_data_create() was never called, so you
passed NULL matchdata to pcre2_match(), hence the failure.

See the attached fix.

The tests still do not pass, but that's probably another (PCRE2) problem.
I hope I helped you at lest somehow.

-- Petr
From 5e28aa58b19fdbfe485f50668c3176fe23e25609 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <[email protected]>
Date: Fri, 9 Dec 2016 14:59:57 +0100
Subject: [PATCH] Fix never match
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

PCRE2 always requires pcre2_match_data_create(). Otherwise
pcre2_match() returns PCRE2_ERROR_NULL.

Signed-off-by: Petr Písař <[email protected]>
---
 server/util_pcre.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/server/util_pcre.c b/server/util_pcre.c
index 845dd33..0c435ff 100644
--- a/server/util_pcre.c
+++ b/server/util_pcre.c
@@ -248,13 +248,13 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, 
const char *buff,
 
     ((ap_regex_t *)preg)->re_erroffset = (apr_size_t)(-1);    /* Only has 
meaning after compile */
 
-    if (nmatch > 0) {
 #ifdef HAVE_PCRE2
-        matchdata = pcre2_match_data_create(nmatch, NULL);
-        if (matchdata == NULL)
-            return AP_REG_ESPACE;
-        ovector = pcre2_get_ovector_pointer(matchdata);
+    matchdata = pcre2_match_data_create(nmatch, NULL);
+    if (matchdata == NULL)
+        return AP_REG_ESPACE;
+    ovector = pcre2_get_ovector_pointer(matchdata);
 #else
+    if (nmatch > 0) {
         if (nmatch <= POSIX_MALLOC_THRESHOLD) {
             ovector = &(small_ovector[0]);
         }
@@ -264,8 +264,8 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, 
const char *buff,
                 return AP_REG_ESPACE;
             allocated_ovector = 1;
         }
-#endif
     }
+#endif
 
 #ifdef HAVE_PCRE2
     rc = pcre2_match((const pcre2_code *)preg->re_pcre,
@@ -290,8 +290,7 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, 
const char *buff,
     }
 
 #ifdef HAVE_PCRE2
-    if (matchdata)
-        pcre2_match_data_free(matchdata);
+    pcre2_match_data_free(matchdata);
 #else
     if (allocated_ovector)
         free(ovector);
-- 
2.7.4

Attachment: signature.asc
Description: PGP signature

Reply via email to