BUG: regex: fix pcre compile error when using JIT

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.
This commit is contained in:
Hiroaki Nakamura 2013-04-11 08:17:37 +02:00 committed by Willy Tarreau
parent f75d008c45
commit e3cf2229ad

View File

@ -544,6 +544,10 @@ int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque, c
{ {
regex *preg; regex *preg;
int icase; int icase;
#ifdef USE_PCRE_JIT
const char *error;
int erroffset;
#endif
preg = calloc(1, sizeof(*preg)); 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 #ifdef USE_PCRE_JIT
icase = (pattern->flags & ACL_PAT_F_IGNORE_CASE) ? PCRE_CASELESS : 0; 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); NULL);
if (!preg->reg) { if (!preg->reg) {
free(preg); free(preg);
memprintf(err, "regex '%s' is invalid", *text); memprintf(err, "regex '%s' is invalid (error=%s, erroffset=%d)", *text, error, erroffset);
return 0; 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) { if (!preg->extra) {
pcre_free(preg->reg); pcre_free(preg->reg);
free(preg); free(preg);
memprintf(err, "failed to compile regex '%s'", *text); memprintf(err, "failed to compile regex '%s' (error=%s)", *text, error);
return 0; return 0;
} }
#else #else