From f53caf1f863f140de1c1af51906e658c9fb7d7d6 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 20 Feb 2019 11:11:12 -0300 Subject: Avoid stack overflow when handling nested captures The C code uses recursion to handle nested captures, so a too deep nesting could create a stack overflow. The fix limits the handling of nested captures to 'MAXRECLEVEL' (default is 200 levels). --- lpvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lpvm.c') diff --git a/lpvm.c b/lpvm.c index 52c14ae..813d3fb 100644 --- a/lpvm.c +++ b/lpvm.c @@ -296,7 +296,8 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, CapState cs; int rem, res, n; int fr = lua_gettop(L) + 1; /* stack index of first result */ - cs.s = o; cs.L = L; cs.ocap = capture; cs.ptop = ptop; + cs.reclevel = 0; cs.L = L; + cs.s = o; cs.ocap = capture; cs.ptop = ptop; n = runtimecap(&cs, capture + captop, s, &rem); /* call function */ captop -= n; /* remove nested captures */ ndyncap -= rem; /* update number of dynamic captures */ -- cgit v1.2.3-55-g6feb