From: phk Date: Mon, 31 Jul 2006 22:09:42 +0000 (+0000) Subject: Always NUL terminate shmlog entries. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10068174d5edcb302ea467d6b09f4c269ee45645;p=varnish Always NUL terminate shmlog entries. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@581 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/shmlog.c b/varnish-cache/bin/varnishd/shmlog.c index 05a18c48..6bd3c278 100644 --- a/varnish-cache/bin/varnishd/shmlog.c +++ b/varnish-cache/bin/varnishd/shmlog.c @@ -66,17 +66,18 @@ VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e) 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 @@ VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...) 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 @@ VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...) 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)); diff --git a/varnish-cache/bin/varnishlog/varnishlog.c b/varnish-cache/bin/varnishlog/varnishlog.c index b5933740..73834c39 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.c +++ b/varnish-cache/bin/varnishlog/varnishlog.c @@ -259,7 +259,7 @@ main(int argc, char **argv) } 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++; diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c index a2927152..f162718d 100644 --- a/varnish-cache/lib/libvarnishapi/shmlog.c +++ b/varnish-cache/lib/libvarnishapi/shmlog.c @@ -22,7 +22,7 @@ struct VSL_data { 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 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp) 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 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp) vd->ptr = p; return (0); } - vd->ptr = p + p[1] + 4; + vd->ptr = p + p[1] + 5; *pp = p; return (1); }