git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH v3] grep: treat PCRE2 jit compilation memory error as non fatal

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Aug 4, 2019, 03:14 UTC
Message-ID
<20190804031409.32764-1-carenas@gmail.com>
In-Reply-To
<20190729105955.44390-1-carenas@gmail.com>

94da9193a6 (grep: add support for PCRE v2, 2017-06-01) uses the JIT fast path unless JIT support has not been compiled in the linked library.

Starting from 10.23 of PCRE2, pcre2grep ignores any errors from pcre2_jit_cpmpile as a workaround for their bug1749[1] and we should do too, so that the interpreter could be used as a fallback in cases where JIT was not available because of a security policy.

To be conservative, we are restricting initially the error to the known error that would be returned in that case (and to be documented as such in a future release of PCRE) and printing a warning so that corrective action could be taken.

[1] https://bugs.exim.org/show_bug.cgi?id=1749
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 grep.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/grep.c b/grep.c
index f7c3a5803e..593a1cb7a0 100644
--- a/grep.c
+++ b/grep.c
@@ -525,7 +525,13 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
 	if (p->pcre2_jit_on == 1) {
 		jitret = pcre2_jit_compile(p->pcre2_pattern, PCRE2_JIT_COMPLETE);
 		if (jitret)
-			die("Couldn't JIT the PCRE2 pattern '%s', got '%d'\n", p->pattern, jitret);
+			if (jitret == PCRE2_ERROR_NOMEMORY) {
+				warning("JIT couldn't be used in PCRE2");
+				p->pcre2_jit_on = 0;
+				return;
+			}
+			else
+				die("Couldn't JIT the PCRE2 pattern '%s', got '%d'\n", p->pattern, jitret);
 
 		/*
 		 * The pcre2_config(PCRE2_CONFIG_JIT, ...) call just
-- 
2.23.0.rc1
Previous: Carlo ArenasNext: Carlo Arenas
Message 20 of 23 in “grep: allow for run time disabling of JIT in PCRE”
  1. grep: allow for run time disabling of JIT in PCRECarlo Marcelo Arenas Belón, Jul 28, 2019
  2. Carlo ArenasJul 29, 2019
  3. Junio C HamanoJul 29, 2019
  4. Carlo ArenasJul 29, 2019
  5. Ævar Arnfjörð BjarmasonJul 29, 2019
  6. Carlo ArenasJul 29, 2019
  7. Ævar Arnfjörð BjarmasonJul 29, 2019
  8. Carlo ArenasJul 30, 2019
  9. grep: allow for run time disabling of JIT in PCRECarlo Marcelo Arenas Belón, Jul 29, 2019
  10. Carlo ArenasJul 29, 2019
  11. René ScharfeJul 29, 2019
  12. Junio C HamanoJul 29, 2019
  13. Carlo ArenasJul 30, 2019
  14. René ScharfeJul 30, 2019
  15. Johannes SchindelinJul 31, 2019
  16. Junio C HamanoJul 31, 2019
  17. Johannes SchindelinJul 31, 2019
  18. Ævar Arnfjörð BjarmasonJul 31, 2019
  19. Carlo ArenasAug 4, 2019
  20. grep: treat PCRE2 jit compilation memory error as non fatalCarlo Marcelo Arenas Belón, Aug 4, 2019
  21. Carlo ArenasAug 4, 2019
  22. Junio C HamanoAug 5, 2019
  23. Johannes SchindelinJul 31, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.