[master] 7574ac639 vgc: Assert on ctx->method also for custom subs
Nils Goroll
nils.goroll at uplex.de
Mon Feb 8 17:52:04 UTC 2021
commit 7574ac63950e7adb963da2a085090c6e8349ae66
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Sat Jan 30 21:09:19 2021 +0100
vgc: Assert on ctx->method also for custom subs
Improve safety by asserting that a sub is never called from a context
which is not allowed as per its okmask.
This is to ensure correctness of our compile- and runtime-checks.
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index f3a87aa39..20aac191d 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -171,6 +171,8 @@ static void
vcc_EmitProc(struct vcc *tl, struct proc *p)
{
struct vsb *vsbm;
+ unsigned mask;
+ const char *maskcmp;
AN(p->okmask);
AZ(VSB_finish(p->cname));
@@ -178,6 +180,14 @@ vcc_EmitProc(struct vcc *tl, struct proc *p)
AZ(VSB_finish(p->body));
AN(p->sym);
+ if (p->method) {
+ mask = p->method->bitval;
+ maskcmp = "==";
+ } else {
+ mask = p->okmask;
+ maskcmp = "&";
+ }
+
Fh(tl, 1, "vcl_func_f %s;\n", VSB_data(p->cname));
Fh(tl, 1, "const struct vcl_sub sub_%s[1] = {{\n",
VSB_data(p->cname));
@@ -201,15 +211,12 @@ vcc_EmitProc(struct vcc *tl, struct proc *p)
p->method && p->method->bitval & VCL_MET_TASK_H ?
"v_dont_optimize " : "");
Fc(tl, 1, "%s(VRT_CTX)\n{\n", VSB_data(p->cname));
- if (p->method) {
- vsbm = VSB_new_auto();
- AN(vsbm);
- vcc_vcl_met2c(vsbm, p->method->bitval);
- AZ(VSB_finish(vsbm));
- Fc(tl, 1, " assert(ctx->method == (%s));\n",
- VSB_data(vsbm));
- VSB_destroy(&vsbm);
- }
+ vsbm = VSB_new_auto();
+ AN(vsbm);
+ vcc_vcl_met2c(vsbm, mask);
+ AZ(VSB_finish(vsbm));
+ Fc(tl, 1, " assert(ctx->method %s (%s));\n", maskcmp, VSB_data(vsbm));
+ VSB_destroy(&vsbm);
Fc(tl, 1, "%s\n%s}\n", VSB_data(p->prologue), VSB_data(p->body));
VSB_destroy(&p->body);
VSB_destroy(&p->prologue);
More information about the varnish-commit
mailing list