Skip to content

warn when PCRE2 JIT compilation fails - #124

Open
teruteru128 wants to merge 1 commit into
cathugger:masterfrom
teruteru128:pcre2-jit-warning
Open

teruteru128 wants to merge 1 commit into
cathugger:masterfrom
teruteru128:pcre2-jit-warning

Conversation

@teruteru128

Copy link
Copy Markdown

filters_add() currently discards the result of pcre2_jit_compile():

// attempt to JIT. ignore error
(void) pcre2_jit_compile(re,PCRE2_JIT_COMPLETE);

When that call fails, matching quietly falls back to the interpreter.
DOFILTER runs pcre2_match() once per filter for every key that is
generated, so this is the hottest path in a PCRE2 build, and nothing
tells the user that it is now running the slow way.

It fails in two situations that are easy to walk into: a PCRE2 built
without JIT support, where every pattern comes back with "bad JIT
option", and a system that refuses the executable mapping JIT needs,
such as a hardened kernel or a W^X policy. Oversized patterns are not
the concern here; the compiler's own "regular expression is too large"
limit is reached first and is already reported.

This warns once, and only when not running quietly, so a filter file
with a thousand patterns still produces a single line. JIT failure stays
non-fatal, and nothing is printed when JIT succeeds.

Tested by forcing pcre2_jit_compile() to fail with a bad option:
one warning is printed for a file with several filters, -q suppresses
it, and an unmodified build stays silent.

JIT failure was silently ignored, leaving matching to run on the much
slower interpreter with no indication of it. Warn once, and only when
not running quietly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant