[master] e6193fb46 Support dquote-delimited fields in VSL records
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Thu Oct 24 16:58:06 UTC 2019
commit e6193fb46dd225c3f68317af82b69c94561f5766
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Fri Dec 21 11:05:31 2018 +0100
Support dquote-delimited fields in VSL records
When we output a VSL field containing spaces, all bets are off for VSL
queries relying on that field or subsequent fields in the same record.
The solution is to allow a quoted-string format for such fields.
diff --git a/bin/varnishtest/tests/r02872.vtc b/bin/varnishtest/tests/r02872.vtc
new file mode 100644
index 000000000..e43af59cb
--- /dev/null
+++ b/bin/varnishtest/tests/r02872.vtc
@@ -0,0 +1,26 @@
+varnishtest "VSL quoted fields"
+
+varnish v1 -vcl {
+ import std;
+ backend be none;
+ sub vcl_recv {
+ # a series of 3-fields log records
+ std.log({" custom log "ok" "});
+ std.log({" "valid" "fields" ok "});
+ std.log({" "missing""blank" ko "});
+ std.log({" missing dquote "ko "});
+ # "
+ return (synth(200));
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.status == 200
+} -run
+
+# records with malformed fields don't show up
+shell -expect "2" {
+ varnishlog -d -n ${v1_name} -g raw -q 'VCL_Log[3]' | wc -l
+}
diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c
index a60bc6017..227591190 100644
--- a/lib/libvarnishapi/vsl_query.c
+++ b/lib/libvarnishapi/vsl_query.c
@@ -122,7 +122,7 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
double lhs_float = 0.;
const char *b, *e, *q;
char *p;
- int i;
+ int i, dq;
AN(vex);
AN(rec);
@@ -144,15 +144,40 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
/* Field */
if (vex->lhs->field > 0) {
- for (e = b, i = 0; *e && i < vex->lhs->field; i++) {
+ for (e = b, i = 0, dq = 0; *e && i < vex->lhs->field; i++) {
+ /* Skip end of previous field */
+ if (dq) {
+ assert(e > b);
+ assert(*e == '"');
+ dq = 0;
+ e++;
+ if (*e == '\0')
+ break;
+ if (!isspace(*e))
+ return (0);
+ }
+
b = e;
/* Skip ws */
while (*b && isspace(*b))
b++;
+
+ dq = (*b == '"');
+ if (dq)
+ b++;
e = b;
- /* Skip non-ws */
- while (*e && !isspace(*e))
- e++;
+
+ if (dq) {
+ /* Find end of string */
+ while (*e && *e != '"')
+ e++;
+ if (*e != '"')
+ return (0);
+ } else {
+ /* Skip non-ws */
+ while (*e && !isspace(*e))
+ e++;
+ }
}
assert(b <= e);
if (*b == '\0' || i < vex->lhs->field)
More information about the varnish-commit
mailing list