aboutsummaryrefslogtreecommitdiff
path: root/lpvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-02-20 11:11:12 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-02-20 11:11:12 -0300
commitf53caf1f863f140de1c1af51906e658c9fb7d7d6 (patch)
tree440889bf7622e7706e6bebe91d7d13ade83a89cc /lpvm.c
parentcc583a17df76a363e419c960d72422169fae816d (diff)
downloadlpeg-f53caf1f863f140de1c1af51906e658c9fb7d7d6.tar.gz
lpeg-f53caf1f863f140de1c1af51906e658c9fb7d7d6.tar.bz2
lpeg-f53caf1f863f140de1c1af51906e658c9fb7d7d6.zip
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).
Diffstat (limited to 'lpvm.c')
-rw-r--r--lpvm.c3
1 files changed, 2 insertions, 1 deletions
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,
296 CapState cs; 296 CapState cs;
297 int rem, res, n; 297 int rem, res, n;
298 int fr = lua_gettop(L) + 1; /* stack index of first result */ 298 int fr = lua_gettop(L) + 1; /* stack index of first result */
299 cs.s = o; cs.L = L; cs.ocap = capture; cs.ptop = ptop; 299 cs.reclevel = 0; cs.L = L;
300 cs.s = o; cs.ocap = capture; cs.ptop = ptop;
300 n = runtimecap(&cs, capture + captop, s, &rem); /* call function */ 301 n = runtimecap(&cs, capture + captop, s, &rem); /* call function */
301 captop -= n; /* remove nested captures */ 302 captop -= n; /* remove nested captures */
302 ndyncap -= rem; /* update number of dynamic captures */ 303 ndyncap -= rem; /* update number of dynamic captures */