diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-10-01 20:40:36 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-10-01 20:40:36 -0700 |
| commit | 44f86084670714c8bb92629b2c6d8cf84fe43acc (patch) | |
| tree | c6949c110c5009ca98912903cf6e1d29188a1a68 | |
| parent | 9648eb66d3a91b055981305ff6dc8d2bcf96c81f (diff) | |
Fix for infinite loop in left recursive patterns
| -rw-r--r-- | match.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -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; |
