r581 - in trunk/varnish-cache: bin/varnishd bin/varnishlog lib/libvarnishapi

phk at projects.linpro.no phk at projects.linpro.no
Tue Aug 1 00:09:42 CEST 2006


Author: phk
Date: 2006-08-01 00:09:42 +0200 (Tue, 01 Aug 2006)
New Revision: 581

Modified:
   trunk/varnish-cache/bin/varnishd/shmlog.c
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
   trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
Always NUL terminate shmlog entries.


Modified: trunk/varnish-cache/bin/varnishd/shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/shmlog.c	2006-07-31 21:49:29 UTC (rev 580)
+++ trunk/varnish-cache/bin/varnishd/shmlog.c	2006-07-31 22:09:42 UTC (rev 581)
@@ -66,17 +66,18 @@
 	assert(loghead->ptr < loghead->size);
 
 	/* Wrap if necessary */
-	if (loghead->ptr + 4 + l + 1 > loghead->size)
+	if (loghead->ptr + 5 + l + 1 > loghead->size)
 		vsl_wrap();
 	p = logstart + loghead->ptr;
 	p[1] = l & 0xff;
 	p[2] = (id >> 8) & 0xff;
 	p[3] = id & 0xff;
 	memcpy(p + 4, b, l);
-	p[4 + l] = SLT_ENDMARKER;
+	p[4 + l] = '\0';
+	p[5 + l] = SLT_ENDMARKER;
 	p[0] = tag;
 
-	loghead->ptr += 4 + l;
+	loghead->ptr += 5 + l;
 	assert(loghead->ptr < loghead->size);
 	AZ(pthread_mutex_unlock(&vsl_mutex));
 }
@@ -95,7 +96,7 @@
 	assert(loghead->ptr < loghead->size);
 
 	/* Wrap if we cannot fit a full size record */
-	if (loghead->ptr + 4 + 255 + 1 > loghead->size) 
+	if (loghead->ptr + 5 + 255 + 1 > loghead->size) 
 		vsl_wrap();
 
 	p = logstart + loghead->ptr;
@@ -108,10 +109,11 @@
 	p[1] = n & 0xff;
 	p[2] = (id >> 8) & 0xff;
 	p[3] = id & 0xff;
-	p[4 + n] = SLT_ENDMARKER;
+	p[4 + n] = '\0';;
+	p[5 + n] = SLT_ENDMARKER;
 	p[0] = tag;
 
-	loghead->ptr += 4 + n;
+	loghead->ptr += 5 + n;
 	assert(loghead->ptr < loghead->size);
 	
 	AZ(pthread_mutex_unlock(&vsl_mutex));

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-07-31 21:49:29 UTC (rev 580)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-07-31 22:09:42 UTC (rev 581)
@@ -259,7 +259,7 @@
 		}
 		v = 0;
 		if (wfile != NULL) {
-			i = fwrite(p, 4 + p[1], 1, wfile);
+			i = fwrite(p, 5 + p[1], 1, wfile);
 			if (i != 1)
 				perror(w_opt);
 			u++;

Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2006-07-31 21:49:29 UTC (rev 580)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2006-07-31 22:09:42 UTC (rev 581)
@@ -22,7 +22,7 @@
 	unsigned char		*ptr;
 
 	FILE			*fi;
-	unsigned char		rbuf[4 + 255 + 1];
+	unsigned char		rbuf[5 + 255 + 1];
 
 	int			b_opt;
 	int			c_opt;
@@ -140,11 +140,9 @@
 		i = fread(vd->rbuf, 4, 1, vd->fi);
 		if (i != 1)
 			return (-1);
-		if (vd->rbuf[1] > 0) {
-			i = fread(vd->rbuf + 4, vd->rbuf[1], 1, vd->fi);
-			if (i != 1)
-				return (-1);
-		}
+		i = fread(vd->rbuf + 4, vd->rbuf[1] + 1, 1, vd->fi);
+		if (i != 1)
+			return (-1);
 		*pp = vd->rbuf;
 		return (1);
 	}
@@ -159,7 +157,7 @@
 			vd->ptr = p;
 			return (0);
 		}
-		vd->ptr = p + p[1] + 4;
+		vd->ptr = p + p[1] + 5;
 		*pp = p;
 		return (1);
 	}




More information about the varnish-commit mailing list