From a15ca394c92ccf402100a2a138de28bc1729291d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Mon, 10 Apr 2023 23:22:53 -0700
Subject: [PATCH] pcre: correct overpessimistic error checking of
 pcre2_jit_compile()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/pcresearch.c: fix implementation to match documentation[1]
keep the fatal error only for the error message that warrants it and that
would be indicative of a bug (PCRE2_ERROR_JIT_BADOPTION) and make the
commonly triggered (ex: under SELinux) PCRE2_ERROR_NOMEMORY and that is
meant to be ignored.

[1] https://pcre2project.github.io/pcre2/doc/html/pcre2_jit_compile.html

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 src/pcresearch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pcresearch.c b/src/pcresearch.c
index 9e2f393..cd6ce71 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -244,8 +244,8 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact)
   pc->data = pcre2_match_data_create_from_pattern (pc->cre, gcontext);
 
   ec = pcre2_jit_compile (pc->cre, PCRE2_JIT_COMPLETE);
-  if (ec && ec != PCRE2_ERROR_JIT_BADOPTION && ec != PCRE2_ERROR_NOMEMORY)
-    die (EXIT_TROUBLE, 0, _("JIT internal error: %d"), ec);
+  if (ec < 0 && ec == PCRE2_ERROR_JIT_BADOPTION)
+    die (EXIT_TROUBLE, 0, _("JIT unexpected internal error: %d"), ec);
 
   /* The PCRE documentation says that a 32 KiB stack is the default.  */
   pc->jit_stack = NULL;
-- 
2.39.2 (Apple Git-143)

