aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-10-01 20:40:36 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-10-01 20:40:36 -0700
commit44f86084670714c8bb92629b2c6d8cf84fe43acc (patch)
treec6949c110c5009ca98912903cf6e1d29188a1a68
parent9648eb66d3a91b055981305ff6dc8d2bcf96c81f (diff)
Fix for infinite loop in left recursive patterns
-rw-r--r--match.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/match.c b/match.c
index 7715ed3..2156e05 100644
--- a/match.c
+++ b/match.c
@@ -205,6 +205,7 @@ static inline pat_t *deref(match_ctx_t *ctx, pat_t *pat)
//
static pat_t *get_prerequisite(match_ctx_t *ctx, pat_t *pat)
{
+ int derefs = 0;
for (pat_t *p = pat; p; ) {
switch (p->type) {
case BP_BEFORE:
@@ -226,6 +227,7 @@ static pat_t *get_prerequisite(match_ctx_t *ctx, pat_t *pat)
case BP_REPLACE:
p = p->args.replace.pat; break;
case BP_REF: {
+ if (++derefs > 10) return p;
pat_t *p2 = deref(ctx, p);
if (p2 == p) return p2;
p = p2;