vtest "Test recursive regexp's fail before consuming all the stack"

# Use 64bit defaults also on 32bit
vinyl v1 -cliok "param.set workspace_client 64k"
vinyl v1 -cliok "param.set http_req_size 32k"

# If you want to play around, uncomment the next lines and adjust
# the length of the ABAB strings below to suit your needs.
# Better yet:  Rewrite your regexps to avoid this madness.

# Tweaks you may add to this test:
# vinyl v1 -cliok "param.set thread_pool_stack 48k"
# vinyl v1 -cliok "param.set pcre2_match_limit 100"
# vinyl v1 -cliok "param.set pcre2_depth_limit 10000"
# vinyl v1 -cliok "param.set pcre2_jit_compilation off"

# Approximate formula for FreeBSD/amd64:
#	pcre2_depth_limit = thread_pool_stack * 2 - 9

vinyl v1 -vcl+backend {
	backend proforma none;

	sub vcl_recv {
		return (synth(200));
	}
	sub vcl_synth {
		# shamelessly copied from "bugzilla77 at gmail dot com"
		# https://bugs.php.net/bug.php?id=70110
		if (req.url ~ "^/(A{1,2}B)+$") {
			set resp.http.found = "1";
		}
	}
} -start

# This should succeed with default params and JIT/no-JIT
client c1 {
	txreq -url "/ABAABABAABABABAB"
	rxresp
	expect resp.status == 200
	expect resp.http.found == 1
} -run

logexpect l1 -v v1 {
	expect * * VCL_Error "(match|depth|recursion|JIT stack) limit"
} -start

# This should fail with default params and JIT/no-JIT
client c1 {
	txreq -url "/${string,repeat,8192,AB}"
	rxresp
	expect resp.status == 500
	expect_close
} -run

logexpect l1 -wait
