[master] e2dbf2148 [ncsa] -j will escape control characters

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 30 08:46:05 UTC 2021


commit e2dbf214896d0975b6b67d87cf588124d99ad25f
Author: Guillaume Quintard <guillaume at varnish-software.com>
Date:   Mon Jun 21 14:53:15 2021 -0700

    [ncsa] -j will escape control characters

diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index d394220be..9c9faf8f6 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -572,7 +572,7 @@ addf_vsl(enum VSL_tag_e tag, long i, const char *prefix)
 
 	ALLOC_OBJ(w, VSL_WATCH_MAGIC);
 	AN(w);
-	if (VSL_tagflags[tag])
+	if (VSL_tagflags[tag] && CTX.quote_how != VSB_QUOTE_JSON)
 		VUT_Error(vut, 1, "Tag %s can contain control characters",
 		    VSL_tags[tag]);
 	w->tag = tag;
@@ -921,7 +921,6 @@ process_vsl(const struct vsl_watch_head *head, enum VSL_tag_e tag,
 {
 	struct vsl_watch *w;
 	const char *p;
-
 	VTAILQ_FOREACH(w, head, list) {
 		CHECK_OBJ_NOTNULL(w, VSL_WATCH_MAGIC);
 		if (tag != w->tag)
@@ -966,13 +965,16 @@ dispatch_f(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 		skip = 0;
 		while (skip == 0 && 1 == VSL_Next(t->c)) {
 			tag = VSL_TAG(t->c->rec.ptr);
-			if (VSL_tagflags[tag])
+			if (VSL_tagflags[tag] &&
+			    CTX.quote_how != VSB_QUOTE_JSON)
 				continue;
 
 			b = VSL_CDATA(t->c->rec.ptr);
 			e = b + VSL_LEN(t->c->rec.ptr);
-			while (e > b && e[-1] == '\0')
-				e--;
+			if (!VSL_tagflags[tag]) {
+				while (e > b && e[-1] == '\0')
+					e--;
+			}
 
 			switch (tag) {
 			case SLT_HttpGarbage:
diff --git a/bin/varnishtest/tests/u00017.vtc b/bin/varnishtest/tests/u00017.vtc
new file mode 100644
index 000000000..a7fa82598
--- /dev/null
+++ b/bin/varnishtest/tests/u00017.vtc
@@ -0,0 +1,31 @@
+varnishtest "SLT_Debug can be printed by varnishncsa -j"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	import cookie;
+
+	sub vcl_recv {
+		cookie.parse("");
+	}
+} -start
+
+varnish v1 -cliok "param.show vsl_mask +Debug"
+
+client c1 {
+	txreq
+	rxresp
+} -run
+
+# Let's fist create a script to reduce in all the variants below.
+
+shell {
+	varnishncsa -d -n ${v1_name} -F '%{VSL:Debug}x' -j | grep "^cookie: nothing to parse\\\\u0000"
+}
+
+shell -err -expect "Tag Debug can contain control characters" {
+	varnishncsa -d -n ${v1_name} -F '%{VSL:Debug}x'
+}
diff --git a/doc/changes.rst b/doc/changes.rst
index 59ed9eef3..0588c5359 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -57,6 +57,8 @@ Varnish Cache 7.x.x (2021-09-15)
 
 * ACLs default to `pedantic` which is now a per-ACL feature flag.
 
+* `varnishncsa -j` will now accept to print fields with control characters.
+
 ================================
 Varnish Cache 6.6.0 (2021-03-15)
 ================================


More information about the varnish-commit mailing list