aboutsummaryrefslogtreecommitdiff
path: root/test.lua
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 /test.lua
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 'test.lua')
-rwxr-xr-xtest.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/test.lua b/test.lua
index 476da0a..8f9f574 100755
--- a/test.lua
+++ b/test.lua
@@ -424,6 +424,16 @@ do
424end 424end
425 425
426 426
427do
428 -- nesting of captures too deep
429 local p = m.C(1)
430 for i = 1, 300 do
431 p = m.Ct(p)
432 end
433 checkerr("too deep", p.match, p, "x")
434end
435
436
427-- tests for non-pattern as arguments to pattern functions 437-- tests for non-pattern as arguments to pattern functions
428 438
429p = { ('a' * m.V(1))^-1 } * m.P'b' * { 'a' * m.V(2); m.V(1)^-1 } 439p = { ('a' * m.V(1))^-1 } * m.P'b' * { 'a' * m.V(2); m.V(1)^-1 }