Commit 09bf7d52 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Always NUL terminate shmlog entries.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@581 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 1ede0729
......@@ -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));
......
......@@ -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++;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment