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

feature pcre_jit

server s1 {
	rxreq
	expect req.http.found == "1"
	txresp
	rxreq
	expect req.http.found == <undef>
	txresp
} -start

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

# varnish v1 -arg "-p thread_pool_stack=48k"
# varnish v1 -arg "-p pcre_match_limit=1000"
# varnish v1 -arg "-p pcre_match_limit_recursion=89"

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

varnish v1 -vcl+backend {
	sub vcl_recv {
		if (req.url ~ "^/a((?!/.).)*$") {
			set req.http.found = "1";
		}
	}
} -start

# This should succeed with default params and JIT/no-JIT
client c1 {
	txreq -url /aaaaaaaa
	rxresp
} -run

# PCRE_ERROR_RECURSIONLIMIT  (-21)
# PCRE_ERROR_JIT_STACKLIMIT  (-27)
logexpect l1 -v v1 {
	expect * * VCL_Error "Regexp matching returned -2[71]"
} -start

# This should fail with default params and JIT/no-JIT
client c1 {
	txreq -url /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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