From 1c1685861e0d304f60f0669c6dbd5005349262e4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 24 Jun 2021 19:44:54 -0700 Subject: txr: stack protection in pattern language. * txr.c (do_match_line, match_files): call gc_stack_check on entry. * tests/012/stack2.txr: New file. * tests/012/stack2.expected: New file. --- match.c | 4 ++++ tests/012/stack2.expected | 1 + tests/012/stack2.txr | 8 ++++++++ 3 files changed, 13 insertions(+) create mode 100644 tests/012/stack2.expected create mode 100644 tests/012/stack2.txr diff --git a/match.c b/match.c index 3f47ee05..a7a22f4b 100644 --- a/match.c +++ b/match.c @@ -1533,6 +1533,8 @@ static val do_match_line(match_line_ctx *c) { val lfe_save = set_last_form_evaled(nil); + gc_stack_check(); + while (c->specline) { val elem = first(c->specline); @@ -4616,6 +4618,8 @@ static val match_files(match_files_ctx c) { gc_hint(c.data); + gc_stack_check(); + for (; c.spec; c.spec = rest(c.spec), c.data = rest(c.data), c.data_lineno = plus(c.data_lineno, one)) diff --git a/tests/012/stack2.expected b/tests/012/stack2.expected new file mode 100644 index 00000000..cad99e12 --- /dev/null +++ b/tests/012/stack2.expected @@ -0,0 +1 @@ +caught diff --git a/tests/012/stack2.txr b/tests/012/stack2.txr new file mode 100644 index 00000000..df9e209a --- /dev/null +++ b/tests/012/stack2.txr @@ -0,0 +1,8 @@ +@(define recur ()) +@(recur) +@(end) +@(try) +@(recur) +@(catch stack-overflow (arg)) +@(do (put-line "caught")) +@(end) -- cgit v1.2.3