diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-02-20 11:11:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-02-20 11:11:12 -0300 |
commit | f53caf1f863f140de1c1af51906e658c9fb7d7d6 (patch) | |
tree | 440889bf7622e7706e6bebe91d7d13ade83a89cc /lpvm.c | |
parent | cc583a17df76a363e419c960d72422169fae816d (diff) | |
download | lpeg-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.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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 */ |