]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG: regex: fix pcre compile error when using JIT
authorHiroaki Nakamura <hnakamur@gmail.com>
Thu, 11 Apr 2013 06:17:37 +0000 (08:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 11 Apr 2013 06:17:37 +0000 (08:17 +0200)
According to "man pcreapi", pcre_compile() does not accept being passed
a NULL pointer in errptr or erroffset. It immediately returns NULL, causing
any expression to fail. So let's pass real variables and make use of them
to improve error reporting.

src/acl.c

index 6a23bae8612708f3f9025c69e6f7980c38ef1082..05bb1a50739b797b5a701ff81c53da7f7c8ee0bd 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -544,6 +544,10 @@ int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque, c
 {
        regex *preg;
        int icase;
+#ifdef USE_PCRE_JIT
+       const char *error;
+       int erroffset;
+#endif
 
        preg = calloc(1, sizeof(*preg));
 
@@ -554,19 +558,19 @@ int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque, c
 
 #ifdef USE_PCRE_JIT
        icase = (pattern->flags & ACL_PAT_F_IGNORE_CASE) ? PCRE_CASELESS : 0;
-       preg->reg = pcre_compile(*text, PCRE_NO_AUTO_CAPTURE | icase, NULL, NULL,
+       preg->reg = pcre_compile(*text, PCRE_NO_AUTO_CAPTURE | icase, &error, &erroffset,
                NULL);
        if (!preg->reg) {
                free(preg);
-               memprintf(err, "regex '%s' is invalid", *text);
+               memprintf(err, "regex '%s' is invalid (error=%s, erroffset=%d)", *text, error, erroffset);
                return 0;
        }
 
-       preg->extra = pcre_study(preg->reg, PCRE_STUDY_JIT_COMPILE, NULL);
+       preg->extra = pcre_study(preg->reg, PCRE_STUDY_JIT_COMPILE, &error);
        if (!preg->extra) {
                pcre_free(preg->reg);
                free(preg);
-               memprintf(err, "failed to compile regex '%s'", *text);
+               memprintf(err, "failed to compile regex '%s' (error=%s)", *text, error);
                return 0;
        }
 #else