diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-11-25 20:08:45 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-11-25 20:10:06 -0800 |
commit | d069525b20e65ef86fb680ba830db634487f111e (patch) | |
tree | b6284c4e89008fcfee6b9a311e35fe12274bb75b /src/pcresearch.c | |
parent | 01fc34d2f121fb36bebe385ed9779e6b052f74b5 (diff) | |
download | grep-d069525b20e65ef86fb680ba830db634487f111e.tar.gz |
grep: port better to Adélie GNU/Linux 64-bit ppc
Problem reported by A. Wilcox (Bug#29446).
* src/pcresearch.c (PCRE_EXTRA_MATCH_LIMIT_RECURSION)
(PCRE_STUDY_EXTRA_NEEDED): Default to 0.
(jit_exec): If we run up against the recursion limit,
double it (if possible) and try again.
(Pcompile): Also specify PCRE_STUDY_EXTRA_NEEDED so that
pc->extra is not null.
Diffstat (limited to 'src/pcresearch.c')
-rw-r--r-- | src/pcresearch.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/pcresearch.c b/src/pcresearch.c index 43f91d08..96b7fc69 100644 --- a/src/pcresearch.c +++ b/src/pcresearch.c @@ -29,9 +29,15 @@ in pcre_exec. */ enum { NSUB = 300 }; +# ifndef PCRE_EXTRA_MATCH_LIMIT_RECURSION +# define PCRE_EXTRA_MATCH_LIMIT_RECURSION 0 +# endif # ifndef PCRE_STUDY_JIT_COMPILE # define PCRE_STUDY_JIT_COMPILE 0 # endif +# ifndef PCRE_STUDY_EXTRA_NEEDED +# define PCRE_STUDY_EXTRA_NEEDED 0 +# endif struct pcre_comp { @@ -83,6 +89,21 @@ jit_exec (struct pcre_comp *pc, char const *subject, int search_bytes, } # endif +# if PCRE_EXTRA_MATCH_LIMIT_RECURSION + if (e == PCRE_ERROR_RECURSIONLIMIT + && (PCRE_STUDY_EXTRA_NEEDED || pc->extra) + && pc->extra->match_limit_recursion <= ULONG_MAX / 2) + { + pc->extra->match_limit_recursion *= 2; + if (pc->extra->match_limit_recursion == 0) + { + pc->extra->match_limit_recursion = (1 << 24) - 1; + pc->extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; + } + continue; + } +# endif + return e; } } @@ -158,7 +179,8 @@ Pcompile (char *pattern, size_t size, reg_syntax_t ignored) if (!pc->cre) die (EXIT_TROUBLE, 0, "%s", ep); - pc->extra = pcre_study (pc->cre, PCRE_STUDY_JIT_COMPILE, &ep); + int pcre_study_flags = PCRE_STUDY_EXTRA_NEEDED | PCRE_STUDY_JIT_COMPILE; + pc->extra = pcre_study (pc->cre, pcre_study_flags, &ep); if (ep) die (EXIT_TROUBLE, 0, "%s", ep); |