r1330 - in branches/1.0: . bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Thu Apr 19 16:50:50 CEST 2007


Author: des
Date: 2007-04-19 16:50:50 +0200 (Thu, 19 Apr 2007)
New Revision: 1330

Modified:
   branches/1.0/
   branches/1.0/bin/varnishd/mgt_cli.c
Log:
 r37063 at cat (orig r1287):  des | 2007-03-29 12:49:58 +0200
 The argv length calculation was not only off by one, but failed to take
 into account the extra space required by expanded quotes, backslashes and
 newlines.  Instead of pre-allocating a (possibly too short) buffer, start
 with a 64-byte buffer and double it every time we come close to filling
 it up.  Also, avoid appending a trailing space before the final newline.
 
 This issue was uncovered by Kristoffer Gleditsch <kristoffer at linpro.no>,
 who also helped test this patch.



Property changes on: branches/1.0
___________________________________________________________________
Name: svk:merge
   - d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1286
   + d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1287

Modified: branches/1.0/bin/varnishd/mgt_cli.c
===================================================================
--- branches/1.0/bin/varnishd/mgt_cli.c	2007-04-19 14:50:48 UTC (rev 1329)
+++ branches/1.0/bin/varnishd/mgt_cli.c	2007-04-19 14:50:50 UTC (rev 1330)
@@ -95,14 +95,23 @@
 		cli_out(cli, "Cache process not running");
 		return;
 	}
-	v = 0;
-	for (u = 1; av[u] != NULL; u++)
-		v += strlen(av[u]) + 3;
+	v = 64;
 	p = malloc(v);
 	XXXAN(p);
 	q = p;
 	for (u = 1; av[u] != NULL; u++) {
+		if (v < (q - p) + 8) {
+			r = realloc(p, v + v);
+			XXXAN(r);
+			v += v;
+			q += r - p;
+			p = r;
+		}
+		/* v >= (q - p) + 8 */
+		if (u > 1)
+			*q++ = ' ';
 		*q++ = '"';
+		/* v >= (q - p) + 6 */
 		for (r = av[u]; *r; r++) {
 			switch (*r) {
 			case '\\':	*q++ = '\\'; *q++ = '\\'; break;
@@ -111,9 +120,10 @@
 			default:	*q++ = *r; break;
 			}
 		}
+		/* v >= (q - p) + 4 */
 		*q++ = '"';
-		*q++ = ' ';
 	}
+	/* v >= (q - p) + 3 */
 	*q++ = '\n';
 	v = q - p;
 	i = write(cli_o, p, v);




More information about the varnish-commit mailing list