r2370 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Jan 23 10:46:14 CET 2008


Author: phk
Date: 2008-01-23 10:46:13 +0100 (Wed, 23 Jan 2008)
New Revision: 2370

Modified:
   trunk/varnish-cache/bin/varnishd/cache_cli.c
   trunk/varnish-cache/bin/varnishd/cache_synthetic.c
   trunk/varnish-cache/bin/varnishd/cache_vary.c
   trunk/varnish-cache/bin/varnishd/mgt_cli.c
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Protect all vsb's (sbufs) with an assert that they did not overflow.

I don't think it is likely that they would, but some users are running
out of memory, so make it deterministic when it happens.

Noticed by Coverity Scan (CID: 4-6)



Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c	2008-01-23 09:26:03 UTC (rev 2369)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c	2008-01-23 09:46:13 UTC (rev 2370)
@@ -125,6 +125,7 @@
 		vsb_clear(cli->sb);
 		cli_dispatch(cli, CLI_cmds, buf);
 		vsb_finish(cli->sb);
+		AZ(vsb_overflowed(cli->sb));
 		i = cli_writeres(heritage.fds[1], cli);
 		if (i) {
 			VSL(SLT_Error, 0, "CLI write failed (errno=%d)", errno);

Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_synthetic.c	2008-01-23 09:26:03 UTC (rev 2369)
+++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c	2008-01-23 09:46:13 UTC (rev 2370)
@@ -118,6 +118,7 @@
 	    "  </body>\n"
 	    "</html>\n");
 	vsb_finish(&vsb);
+	AZ(vsb_overflowed(&vsb));
 	w->acct.hdrbytes = WRK_Write(w, vsb_data(&vsb), vsb_len(&vsb));
 	(void)WRK_Flush(w);
 	vsb_delete(&vsb);

Modified: trunk/varnish-cache/bin/varnishd/cache_vary.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vary.c	2008-01-23 09:26:03 UTC (rev 2369)
+++ trunk/varnish-cache/bin/varnishd/cache_vary.c	2008-01-23 09:46:13 UTC (rev 2370)
@@ -91,6 +91,7 @@
 		vsb_clear(sbh);
 		vsb_printf(sbh, "%c%.*s:%c", 1 + (q - p), q - p, p, 0);
 		vsb_finish(sbh);
+		AZ(vsb_overflowed(sbh));
 
 		/* Append to vary matching string */
 		vsb_bcat(sb, vsb_data(sbh), vsb_len(sbh));
@@ -122,6 +123,7 @@
 	vsb_printf(sb, "%c", 0);
 
 	vsb_finish(sb);
+	AZ(vsb_overflowed(sb));
 	l = vsb_len(sb);
 	sp->obj->vary = malloc(l);
 	AN(sp->obj->vary);

Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c	2008-01-23 09:26:03 UTC (rev 2369)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c	2008-01-23 09:46:13 UTC (rev 2370)
@@ -124,6 +124,7 @@
 	vsb_putc(sb, '\n');
 	xxxassert(!vsb_overflowed(sb));
 	vsb_finish(sb);
+	AZ(vsb_overflowed(sb));
 	i = write(cli_o, vsb_data(sb), vsb_len(sb));
 	xxxassert(i == vsb_len(sb));
 	vsb_delete(sb);
@@ -325,6 +326,7 @@
 		vsb_clear(cp->cli->sb);
 		cli_dispatch(cp->cli, cli_proto, p);
 		vsb_finish(cp->cli->sb);
+		AZ(vsb_overflowed(cp->cli->sb));
 
 		/* send the result back */
 		if (cli_writeres(cp->fdo, cp->cli))

Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2008-01-23 09:26:03 UTC (rev 2369)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2008-01-23 09:46:13 UTC (rev 2370)
@@ -237,6 +237,7 @@
 	vsb_new(&cmdsb, cmdline, sizeof cmdline, 0);
 	mgt_make_cc_cmd(&cmdsb, sf, of);
 	vsb_finish(&cmdsb);
+	AZ(vsb_overflowed(&cmdsb));
 	/* XXX check vsb state */
 
 	if (pipe(p) < 0) {
@@ -430,6 +431,7 @@
 		vf = mgt_VccCompileFile(sb, f_arg, C_flag, f_fd);
 	}
 	vsb_finish(sb);
+	AZ(vsb_overflowed(sb));
 	if (vsb_len(sb) > 0)
 		fprintf(stderr, "%s", vsb_data(sb));
 	vsb_delete(sb);
@@ -511,6 +513,7 @@
 	XXXAN(sb);
 	vf = mgt_VccCompile(sb, av[3], NULL, 0);
 	vsb_finish(sb);
+	AZ(vsb_overflowed(sb));
 	if (vsb_len(sb) > 0)
 		cli_out(cli, "%s", vsb_data(sb));
 	vsb_delete(sb);
@@ -544,6 +547,7 @@
 	XXXAN(sb);
 	vf = mgt_VccCompileFile(sb, av[3], 0, -1);
 	vsb_finish(sb);
+	AZ(vsb_overflowed(sb));
 	if (vsb_len(sb) > 0)
 		cli_out(cli, "%s", vsb_data(sb));
 	vsb_delete(sb);

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2008-01-23 09:26:03 UTC (rev 2369)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2008-01-23 09:46:13 UTC (rev 2370)
@@ -342,6 +342,7 @@
 		return;
 	}
 	vsb_finish(cli->sb);
+	AZ(vsb_overflowed(cli->sb));
 	fprintf(stderr, "Error:\n%s\n", vsb_data(cli->sb));
 	exit (2);
 }
@@ -477,6 +478,7 @@
 	if (cli[0].result != CLIS_OK) {
 		fprintf(stderr, "Parameter errors:\n");
 		vsb_finish(cli[0].sb);
+		AZ(vsb_overflowed(cli[0].sb));
 		fprintf(stderr, "%s\n", vsb_data(cli[0].sb));
 		exit(1);
 	}




More information about the varnish-commit mailing list