From f348ecd67ae64ba9b2a10e9efe84e9091af42bb2 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 1 Sep 2022 19:34:00 +0200 Subject: [PATCH] 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. --- src/regex.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/regex.c b/src/regex.c index 45a7e9004e..19c7eda8f5 100644 --- a/src/regex.c +++ b/src/regex.c @@ -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