[master] af8894525 Add m00054.vtc: panic when calling sub from a wrong vcl
Nils Goroll
nils.goroll at uplex.de
Mon Feb 8 17:52:04 UTC 2021
commit af8894525e778adb343847de99c00fa23869a5c9
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Sat Feb 6 14:10:30 2021 +0100
Add m00054.vtc: panic when calling sub from a wrong vcl
VMODs must not use SUB references across VCLs. This test checks for a
panic if they do.
diff --git a/bin/varnishtest/tests/m00054.vtc b/bin/varnishtest/tests/m00054.vtc
new file mode 100644
index 000000000..87b53f591
--- /dev/null
+++ b/bin/varnishtest/tests/m00054.vtc
@@ -0,0 +1,36 @@
+varnishtest "VCL_SUB wrong vmod behavior"
+
+varnish v1 -arg "-p feature=+no_coredump" -vcl {
+ import debug;
+
+ backend dummy None;
+
+ sub foo {
+ set resp.http.it = "works";
+ }
+
+ sub vcl_init {
+ debug.bad_memory(foo);
+ }
+} -start
+
+varnish v1 -vcl {
+ import debug;
+ backend dummy None;
+
+ sub vcl_recv {
+ debug.call(debug.total_recall());
+ }
+
+}
+
+client c1 {
+ txreq -url "/foo"
+ expect_close
+} -run
+
+varnish v1 -wait-stopped
+varnish v1 -cliexpect "Assert error in VPI_Call_Check" "panic.show"
+varnish v1 -cliok "panic.clear"
+varnish v1 -expect MGT.child_panic == 1
+varnish v1 -expectexit 0x40
diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c
index 9d2866de0..25ce2f76e 100644
--- a/vmod/vmod_debug.c
+++ b/vmod/vmod_debug.c
@@ -1309,3 +1309,25 @@ xyzzy_check_call(VRT_CTX, VCL_SUB sub)
{
return (VRT_check_call(ctx, sub));
}
+
+/* the next two are to test WRONG vmod behavior:
+ * holding a VCL_SUB reference across vcls
+ */
+
+static VCL_SUB wrong = NULL;
+
+VCL_VOID v_matchproto_(td_xyzzy_bad_memory)
+xyzzy_bad_memory(VRT_CTX, VCL_SUB sub)
+{
+ (void) ctx;
+
+ wrong = sub;
+}
+
+VCL_SUB v_matchproto_(td_xyzzy_total_recall)
+xyzzy_total_recall(VRT_CTX)
+{
+ (void) ctx;
+
+ return (wrong);
+}
diff --git a/vmod/vmod_debug.vcc b/vmod/vmod_debug.vcc
index cff0a8867..45fc1fdee 100644
--- a/vmod/vmod_debug.vcc
+++ b/vmod/vmod_debug.vcc
@@ -332,3 +332,11 @@ string saying why not.
$Function VOID call(SUB)
Call a sub
+
+$Function VOID bad_memory(SUB)
+
+To test *WRONG* behavior
+
+$Function SUB total_recall()
+
+To test *WRONG* behavior
More information about the varnish-commit
mailing list