r1709 - in branches/1.1: . bin/varnishd lib/libvarnish lib/libvcl

des at projects.linpro.no des at projects.linpro.no
Tue Jul 17 12:15:44 CEST 2007


Author: des
Date: 2007-07-17 12:15:44 +0200 (Tue, 17 Jul 2007)
New Revision: 1709

Modified:
   branches/1.1/
   branches/1.1/bin/varnishd/cache_main.c
   branches/1.1/bin/varnishd/cache_response.c
   branches/1.1/bin/varnishd/cache_vrt.c
   branches/1.1/bin/varnishd/flint.lnt
   branches/1.1/bin/varnishd/mgt_child.c
   branches/1.1/bin/varnishd/storage_file.c
   branches/1.1/lib/libvarnish/cli_common.c
   branches/1.1/lib/libvcl/vcc_compile.c
   branches/1.1/lib/libvcl/vcc_compile.h
   branches/1.1/lib/libvcl/vcc_token.c
   branches/1.1/lib/libvcl/vcc_var.c
Log:
Merged revisions 1693-1708 via svnmerge from 
svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache

........
  r1694 | phk | 2007-07-13 17:31:37 +0200 (Fri, 13 Jul 2007) | 3 lines
  
  Fix 304 responses, they got messed up in the vcl_deliver() addition.
........
  r1695 | phk | 2007-07-13 21:36:38 +0200 (Fri, 13 Jul 2007) | 4 lines
  
  Shave the previos commit a bit closer: don't write the HTTP response
  only to throw it away later and then rewrite it again after giving
  vcl_deliver() the chance to munge it.
........
  r1696 | phk | 2007-07-15 09:51:36 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Tune a couple of library warnings out
........
  r1697 | phk | 2007-07-15 09:52:11 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Make the header-gluing code more readable.
........
  r1698 | phk | 2007-07-15 09:52:30 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  A cast to make flexelint happy.
........
  r1699 | phk | 2007-07-15 12:22:05 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Initialize all bits in the sigaction.
........
  r1700 | phk | 2007-07-15 12:22:39 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Plug a memory-leak in the VCL compiler.
........
  r1701 | phk | 2007-07-15 12:57:55 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Don't leak all the tokens.
........
  r1702 | phk | 2007-07-15 12:58:11 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Plug minor memory leak.
........
  r1703 | phk | 2007-07-15 13:04:52 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Don't leak the file contents either.
........
  r1704 | phk | 2007-07-15 13:08:48 +0200 (Sun, 15 Jul 2007) | 2 lines
  
  Plug even more memory leaks in the VCL compiler.
........
  r1705 | phk | 2007-07-15 13:25:27 +0200 (Sun, 15 Jul 2007) | 13 lines
  
  From the "What has the world come to ?" department:
  
  It used to be that sscanf(3) would walk along the proffered string
  and do what the format string was told, and as long as the format
  terminated before the input string, the NUL termination was not
  relevant.
  
  Sometime in the last 20 years, sscanf started doing a strlen on the
  passed argument changing this behaviour.
  
  Give sscanf the NUL it wants.
........



Property changes on: branches/1.1
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk/varnish-cache:1-1692
   + /trunk/varnish-cache:1-1708

Modified: branches/1.1/bin/varnishd/cache_main.c
===================================================================
--- branches/1.1/bin/varnishd/cache_main.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/bin/varnishd/cache_main.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -71,7 +71,7 @@
 		stevedore->open(stevedore);
 
 	printf("Ready\n");
-	VSL_stats->start_time = TIM_real();
+	VSL_stats->start_time = (time_t)TIM_real();
 
 	CLI_Init();
 

Modified: branches/1.1/bin/varnishd/cache_response.c
===================================================================
--- branches/1.1/bin/varnishd/cache_response.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/bin/varnishd/cache_response.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -69,8 +69,7 @@
 
 	http_ClrHeader(sp->http);
 	sp->http->logtag = HTTP_Tx;
-	http_SetResp(sp->http,
-	    "HTTP/1.1", "304", "Not Modified");
+	http_SetResp(sp->http, "HTTP/1.1", "304", "Not Modified");
 	TIM_format(sp->t_req, lm);
 	http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm);
 	http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
@@ -79,10 +78,7 @@
 	http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Last-Modified: %s", lm);
 	if (sp->doclose != NULL)
 		http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close");
-	WRK_Reset(sp->wrk, &sp->fd);
-	sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
-	if (WRK_Flush(sp->wrk))
-		vca_close_session(sp, "remote closed");
+	sp->wantbody = 0;
 }
 
 /*--------------------------------------------------------------------*/

Modified: branches/1.1/bin/varnishd/cache_vrt.c
===================================================================
--- branches/1.1/bin/varnishd/cache_vrt.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/bin/varnishd/cache_vrt.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -123,28 +123,30 @@
 
 	u = WS_Reserve(hp->ws, 0);
 	e = b = hp->ws->f;
-	*e = '\0';
+	e += u;
 	if (h != NULL) {
 		x = strlen(h);
-		if (x + 2 < u) {
-			memcpy(e, h, x);
-			e[x] = ' ';
-			e[x + 1] = '\0';
-		}
-		e += x + 1;
+		if (b + x < e)
+			memcpy(b, h, x);
+		b += x;
+		if (b + 1 < e) 
+			*b++ = ' ';
 	}
 	while (p != NULL) {
 		x = strlen(p);
-		if (x + 1 < u)
-			memcpy(e, p, x);
-		e += x;
+		if (b + x < e)
+			memcpy(b, p, x);
+		b += x;
 		p = va_arg(ap, const char *);
 	}
-	*e = '\0';
-	if (e > b + u) {
+	if (b + 1 < e) 
+		*b++ = '\0';
+	if (b > e) {
 		WS_Release(hp->ws, 0);
 		return (NULL);
 	} else {
+		e = b;
+		b = hp->ws->f;
 		WS_Release(hp->ws, 1 + e - b);
 		return (b);
 	}

Modified: branches/1.1/bin/varnishd/flint.lnt
===================================================================
--- branches/1.1/bin/varnishd/flint.lnt	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/bin/varnishd/flint.lnt	2007-07-17 10:15:44 UTC (rev 1709)
@@ -3,6 +3,12 @@
 +libh mgt_event.h
 +libh ../../config.h
 
+-emacro((???),va_arg)   // the va_arg() macro can yield 415, 416, 661, 662
+                        // 796 and 797 (out-of-bounds errors).
+-elib(123)  // size is both a variable and a macro with args
+-emacro(736, isnan)  // isnanf
+
+
 -header(../../config.h)
 
 // Fix strchr() semtics, it can only return NULL if arg2 != 0

Modified: branches/1.1/bin/varnishd/mgt_child.c
===================================================================
--- branches/1.1/bin/varnishd/mgt_child.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/bin/varnishd/mgt_child.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -410,6 +410,7 @@
 
 	setproctitle("Varnish-Mgr %s", heritage.name);
 
+	memset(&sac, 0, sizeof sac);
 	sac.sa_handler = SIG_IGN;
 	sac.sa_flags = SA_RESTART;
 

Modified: branches/1.1/bin/varnishd/storage_file.c
===================================================================
--- branches/1.1/bin/varnishd/storage_file.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/bin/varnishd/storage_file.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -317,6 +317,7 @@
 		return;
 	}
 
+
 	asprintf(&q, "%s/varnish.XXXXXX", p);
 	XXXAN(q);
 	sc->fd = mkstemp(q);
@@ -331,6 +332,7 @@
 	XXXAN(sc->filename);
 	free(q);
 	smf_initfile(sc, size, 1);
+	free(p);
 }
 
 /*--------------------------------------------------------------------

Modified: branches/1.1/lib/libvarnish/cli_common.c
===================================================================
--- branches/1.1/lib/libvarnish/cli_common.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/lib/libvarnish/cli_common.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -154,6 +154,7 @@
 	assert(i == CLI_LINE0_LEN);
 	assert(res[3] == ' ');
 	assert(res[CLI_LINE0_LEN - 1] == '\n');
+	res[CLI_LINE0_LEN - 1] = '\0';
 	j = sscanf(res, "%u %u\n", &u, &v);
 	assert(j == 2);
 	if (status != NULL)

Modified: branches/1.1/lib/libvcl/vcc_compile.c
===================================================================
--- branches/1.1/lib/libvcl/vcc_compile.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/lib/libvcl/vcc_compile.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -95,18 +95,26 @@
 
 /*--------------------------------------------------------------------*/
 
+void
+TlFree(struct tokenlist *tl, void *p)
+{
+	struct membit *mb;
+
+	mb = calloc(sizeof *mb, 1);
+	assert(mb != NULL);
+	mb->ptr = p;
+	TAILQ_INSERT_TAIL(&tl->membits, mb, list);
+}
+
+
 void *
 TlAlloc(struct tokenlist *tl, unsigned len)
 {
-	struct membit *mb;
 	void *p;
 
 	p = calloc(len, 1);
 	assert(p != NULL);
-	mb = calloc(sizeof *mb, 1);
-	assert(mb != NULL);
-	mb->ptr = p;
-	TAILQ_INSERT_TAIL(&tl->membits, mb, list);
+	TlFree(tl, p);
 	return (p);
 }
 
@@ -370,6 +378,8 @@
 vcc_destroy_source(struct source *sp)
 {
 
+	if (sp->freeit != NULL)
+		free(sp->freeit);
 	free(sp->name);	
 	free(sp);
 }
@@ -382,6 +392,7 @@
 	char *f;
 	int i;
 	struct stat st;
+	struct source *sp;
 
 	if (fd < 0) {
 		fd = open(fn, O_RDONLY);
@@ -398,7 +409,9 @@
 	assert(i == st.st_size);
 	close(fd);
 	f[i] = '\0';
-	return (vcc_new_source(f, f + i, fn));
+	sp = vcc_new_source(f, f + i, fn);
+	sp->freeit = f;
+	return (sp);
 }
 
 /*--------------------------------------------------------------------*/
@@ -501,6 +514,7 @@
 vcc_DestroyTokenList(struct tokenlist *tl, char *ret)
 {
 	struct membit *mb;
+	struct source *sp;
 	int i;
 
 	while (!TAILQ_EMPTY(&tl->membits)) {
@@ -509,6 +523,11 @@
 		free(mb->ptr);
 		free(mb);
 	}
+	while (!TAILQ_EMPTY(&tl->sources)) {
+		sp = TAILQ_FIRST(&tl->sources);
+		TAILQ_REMOVE(&tl->sources, sp, list);
+		vcc_destroy_source(sp);
+	}
 		
 	vsb_delete(tl->fh);
 	vsb_delete(tl->fc);
@@ -645,7 +664,6 @@
 	if (sp == NULL)
 		return (NULL);
 	r = vcc_CompileSource(sb, sp);
-	vcc_destroy_source(sp);
 	return (r);
 }
 
@@ -664,7 +682,6 @@
 	if (sp == NULL)
 		return (NULL);
 	r = vcc_CompileSource(sb, sp);
-	vcc_destroy_source(sp);
 	return (r);
 }
 

Modified: branches/1.1/lib/libvcl/vcc_compile.h
===================================================================
--- branches/1.1/lib/libvcl/vcc_compile.h	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/lib/libvcl/vcc_compile.h	2007-07-17 10:15:44 UTC (rev 1709)
@@ -45,6 +45,7 @@
 	const char		*b;
 	const char		*e;
 	unsigned		idx;
+	char			*freeit;
 };
 
 struct token {
@@ -153,6 +154,7 @@
 void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...);
 void EncToken(struct vsb *sb, const struct token *t);
 int IsMethod(const struct token *t);
+void TlFree(struct tokenlist *tl, void *p);
 void *TlAlloc(struct tokenlist *tl, unsigned len);
 
 /* vcc_obj.c */

Modified: branches/1.1/lib/libvcl/vcc_token.c
===================================================================
--- branches/1.1/lib/libvcl/vcc_token.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/lib/libvcl/vcc_token.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -209,7 +209,7 @@
 	unsigned char u;
 
 	assert(tl->t->tok == CSTR);
-	tl->t->dec = malloc((tl->t->e - tl->t->b) - 1);
+	tl->t->dec = TlAlloc(tl, (tl->t->e - tl->t->b) - 1);
 	assert(tl->t->dec != NULL);
 	q = tl->t->dec;
 	for (p = tl->t->b + 1; p < tl->t->e - 1; ) {
@@ -255,7 +255,7 @@
 {
 	struct token *t;
 
-	t = calloc(sizeof *t, 1);
+	t = TlAlloc(tl, sizeof *t);
 	assert(t != NULL);
 	t->tok = tok;
 	t->b = b;

Modified: branches/1.1/lib/libvcl/vcc_var.c
===================================================================
--- branches/1.1/lib/libvcl/vcc_var.c	2007-07-16 13:06:42 UTC (rev 1708)
+++ branches/1.1/lib/libvcl/vcc_var.c	2007-07-17 10:15:44 UTC (rev 1709)
@@ -64,10 +64,12 @@
 	asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
 	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
 	AN(p);
+	TlFree(tl, p);
 	v->rname = p;
 	asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
 	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
 	AN(p);
+	TlFree(tl, p);
 	v->lname = p;
 	return (v);
 }




More information about the varnish-commit mailing list