[master] 9d81a71 Error out on comparisons of different types, where stringification wouldn't make sense.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Dec 8 21:48:05 CET 2016
commit 9d81a71a1987f07021ae9f653b0f8f4c54544dbe
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Dec 8 20:46:10 2016 +0000
Error out on comparisons of different types, where stringification
wouldn't make sense.
Fixes: #2099
NB: This _may_ expose certain corner cases of unwise symbol overloading
in VCL.
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 513f56c..cb8ea6e 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -308,3 +308,14 @@ varnish v1 -errvcl {Symbol not found: 'storage.foo' (expected type STEVEDORE):}
set beresp.storage = storage.foo;
}
}
+
+varnish v1 -errvcl {Comparison of different types: BACKEND '==' STRING} {
+ backend b1 { .host = "127.0.0.1"; }
+
+ sub vcl_backend_response {
+ set beresp.http.bereq_backend = bereq.backend;
+ if (bereq.backend == beresp.http.bereq_backend) {
+ set beresp.http.bereq_backend_cmp = "ok";
+ }
+ }
+}
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 0aca3da..9581cbf 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1184,6 +1184,14 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt)
e2 = NULL;
vcc_expr0(tl, &e2, (*e)->fmt);
ERRCHK(tl);
+ if (e2->fmt != (*e)->fmt) {
+ VSB_printf(tl->sb, "Comparison of different types: ");
+ VSB_printf(tl->sb, "%s ", (*e)->fmt->name);
+ vcc_ErrToken(tl, tk);
+ VSB_printf(tl->sb, " %s\n", e2->fmt->name);
+ vcc_ErrWhere(tl, tk);
+ return;
+ }
*e = vcc_expr_edit(BOOL, buf, *e, e2);
return;
}
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 14831b8..21dd348 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -128,7 +128,7 @@ VCC_Symbol(struct vcc *tl, struct symbol *parent,
if (q < e)
break;
if (kind != SYM_NONE && sym->kind != kind)
- continue;
+ break;
if (kind == SYM_NONE && sym->kind == kind)
continue;
break;
More information about the varnish-commit
mailing list