BUG/MINOR: regex: Properly handle PCRE2 lib compiled without JIT support

The PCRE2 JIT support is buggy. If HAProxy is compiled with USE_PCRE2_JIT
option while the PCRE2 library is compiled without the JIT support, any
matching will fail because pcre2_jit_compile() return value is not properly
handled. We must fall back on pcre2_match() if PCRE2_ERROR_JIT_BADOPTION
error is returned.

This patch should fix the issue #1848. It must be backported as far as 2.4.
This commit is contained in:
Christopher Faulet 2022-09-01 19:34:00 +02:00
parent 32872db605
commit f348ecd67a
1 changed files with 9 additions and 5 deletions

View File

@ -372,12 +372,16 @@ struct my_regex *regex_comp(const char *str, int cs, int cap, char **err)
* We end if it is an error not related to lack of JIT support
* in a case of JIT support missing pcre2_jit_compile is "no-op"
*/
if (jit < 0 && jit != PCRE2_ERROR_JIT_BADOPTION) {
pcre2_code_free(regex->reg);
memprintf(err, "regex '%s' jit compilation failed", str);
goto out_fail_alloc;
} else {
if (!jit)
regex->mfn = &pcre2_jit_match;
else {
if (jit != PCRE2_ERROR_JIT_BADOPTION) {
pcre2_code_free(regex->reg);
memprintf(err, "regex '%s' jit compilation failed", str);
goto out_fail_alloc;
}
else
regex->mfn = &pcre2_match;
}
#endif