Merge branch 'ab/pcre2-grep'
"git grep" compiled with libpcre2 sometimes triggered a segfault, which is being fixed. * ab/pcre2-grep: grep: fix segfault under -P + PCRE2 <=10.30 + (*NO_JIT) test-lib: add LIBPCRE1 & LIBPCRE2 prerequisites
This commit is contained in:
26
grep.c
26
grep.c
@ -477,6 +477,8 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
|
||||
int options = PCRE2_MULTILINE;
|
||||
const uint8_t *character_tables = NULL;
|
||||
int jitret;
|
||||
int patinforet;
|
||||
size_t jitsizearg;
|
||||
|
||||
assert(opt->pcre2);
|
||||
|
||||
@ -511,6 +513,30 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
|
||||
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);
|
||||
|
||||
/*
|
||||
* The pcre2_config(PCRE2_CONFIG_JIT, ...) call just
|
||||
* tells us whether the library itself supports JIT,
|
||||
* but to see whether we're going to be actually using
|
||||
* JIT we need to extract PCRE2_INFO_JITSIZE from the
|
||||
* pattern *after* we do pcre2_jit_compile() above.
|
||||
*
|
||||
* This is because if the pattern contains the
|
||||
* (*NO_JIT) verb (see pcre2syntax(3))
|
||||
* pcre2_jit_compile() will exit early with 0. If we
|
||||
* then proceed to call pcre2_jit_match() further down
|
||||
* the line instead of pcre2_match() we'll either
|
||||
* segfault (pre PCRE 10.31) or run into a fatal error
|
||||
* (post PCRE2 10.31)
|
||||
*/
|
||||
patinforet = pcre2_pattern_info(p->pcre2_pattern, PCRE2_INFO_JITSIZE, &jitsizearg);
|
||||
if (patinforet)
|
||||
BUG("pcre2_pattern_info() failed: %d", patinforet);
|
||||
if (jitsizearg == 0) {
|
||||
p->pcre2_jit_on = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
p->pcre2_jit_stack = pcre2_jit_stack_create(1, 1024 * 1024, NULL);
|
||||
if (!p->pcre2_jit_stack)
|
||||
die("Couldn't allocate PCRE2 JIT stack");
|
||||
|
||||
Reference in New Issue
Block a user