[master] 0d400c3 Don't double backslash-escape panic messages, and be more generous with their length.

Poul-Henning Kamp phk at FreeBSD.org
Thu Feb 2 10:01:05 CET 2017


commit 0d400c38a1800d875296775b315eb9c46a7a7cef
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Feb 2 08:49:59 2017 +0000

    Don't double backslash-escape panic messages, and be more generous
    with their length.

diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index c2ebbf6..0dd2b82 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -200,6 +200,8 @@ vtc_log(struct vtclog *vl, int lvl, const char *fmt, ...)
  * Dump a string
  */
 
+#define MAX_DUMP 8192
+
 void
 vtc_dump(struct vtclog *vl, int lvl, const char *pfx, const char *str, int len)
 {
@@ -214,10 +216,11 @@ vtc_dump(struct vtclog *vl, int lvl, const char *pfx, const char *str, int len)
 		    lead[lvl < 0 ? 1: lvl], vl->id, vl->tx, pfx);
 		if (len < 0)
 			len = strlen(str);
-		VSB_quote_pfx(vl->vsb, buf, str,len > 1024 ? 1024 : len,
-		    VSB_QUOTE_NONL);
-		if (len > 1024)
-			VSB_printf(vl->vsb, "%s [...] (%d)", buf, len - 1024);
+		VSB_quote_pfx(vl->vsb, buf, str,
+		    len > MAX_DUMP ? MAX_DUMP : len, VSB_QUOTE_UNSAFE);
+		if (len > MAX_DUMP)
+			VSB_printf(vl->vsb, "%s [...] (%d)\n",
+			    buf, len - MAX_DUMP);
 	}
 	REL_VL(vl);
 	if (lvl == 0)
diff --git a/include/vsb.h b/include/vsb.h
index 0f5bfdc..3f66897 100644
--- a/include/vsb.h
+++ b/include/vsb.h
@@ -76,10 +76,11 @@ char		*VSB_data(const struct vsb *);
 ssize_t		 VSB_len(const struct vsb *);
 void		 VSB_delete(struct vsb *);
 void		 VSB_destroy(struct vsb **);
-#define VSB_QUOTE_NONL	1
-#define VSB_QUOTE_JSON	2
-#define VSB_QUOTE_HEX	4
-#define VSB_QUOTE_CSTR	8
+#define VSB_QUOTE_NONL		1
+#define VSB_QUOTE_JSON		2
+#define VSB_QUOTE_HEX		4
+#define VSB_QUOTE_CSTR		8
+#define VSB_QUOTE_UNSAFE	16
 void		 VSB_quote_pfx(struct vsb *, const char*, const void *,
 		     int len, int how);
 void		 VSB_quote(struct vsb *, const void *, int len, int how);
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index 93fb65b..cc9e4d0 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -567,13 +567,14 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how)
 			break;
 		case '\\':
 		case '"':
-			(void)VSB_putc(s, '\\');
+			if (!(how & VSB_QUOTE_UNSAFE))
+				(void)VSB_putc(s, '\\');
 			(void)VSB_putc(s, *q);
 			break;
 		case '\n':
 			if (how & VSB_QUOTE_CSTR) {
 				(void)VSB_printf(s, "\\n\"\n%s\t\"", pfx);
-			} else if (how & VSB_QUOTE_NONL) {
+			} else if (how & (VSB_QUOTE_NONL|VSB_QUOTE_UNSAFE)) {
 				(void)VSB_printf(s, "\n");
 				nl = 1;
 			} else {



More information about the varnish-commit mailing list