r4200 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Aug 18 17:48:08 CEST 2009


Author: phk
Date: 2009-08-18 17:48:08 +0200 (Tue, 18 Aug 2009)
New Revision: 4200

Modified:
   trunk/varnish-cache/bin/varnishd/shmlog.c
Log:
Be more paranoid about shmlog magics,

Don't explode manager if it gets overwritten.



Modified: trunk/varnish-cache/bin/varnishd/shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/shmlog.c	2009-08-18 12:19:10 UTC (rev 4199)
+++ trunk/varnish-cache/bin/varnishd/shmlog.c	2009-08-18 15:48:08 UTC (rev 4200)
@@ -72,16 +72,19 @@
 vsl_wrap(void)
 {
 
+	assert(loghead->magic == SHMLOGHEAD_MAGIC);
 	*logstart = SLT_ENDMARKER;
 	logstart[loghead->ptr] = SLT_WRAPMARKER;
 	loghead->ptr = 0;
 	VSL_stats->shm_cycles++;
+	assert(loghead->magic == SHMLOGHEAD_MAGIC);
 }
 
 static void
 vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, unsigned id)
 {
 
+	assert(loghead->magic == SHMLOGHEAD_MAGIC);
 	assert(len < 0x10000);
 	assert(id < 0x10000);
 	p[__SHMLOG_LEN_HIGH] = (len >> 8) & 0xff;
@@ -281,13 +284,18 @@
 void
 VSL_Panic(int *len, char **ptr)
 {
+	static char a[1] = { '\0' }; 
 
 	AN(len);
 	AN(ptr);
-	assert(loghead->magic == SHMLOGHEAD_MAGIC);
-	assert(loghead->hdrsize == sizeof *loghead);
-	*len = sizeof(loghead->panicstr);
-	*ptr = loghead->panicstr;
+	if (loghead->magic == SHMLOGHEAD_MAGIC) {
+		assert(loghead->hdrsize == sizeof *loghead);
+		*len = sizeof(loghead->panicstr);
+		*ptr = loghead->panicstr;
+	} else {
+		*len = 0;
+		*ptr = a;
+	}
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list