Commit f2bd97c7 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

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.
........


git-svn-id: http://www.varnish-cache.org/svn/branches/1.1@1709 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent cb3214a6
......@@ -71,7 +71,7 @@ child_main(void)
stevedore->open(stevedore);
printf("Ready\n");
VSL_stats->start_time = TIM_real();
VSL_stats->start_time = (time_t)TIM_real();
CLI_Init();
......
......@@ -69,8 +69,7 @@ res_do_304(struct sess *sp)
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 @@ res_do_304(struct sess *sp)
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;
}
/*--------------------------------------------------------------------*/
......
......@@ -123,28 +123,30 @@ vrt_assemble_string(struct http *hp, const char *h, const char *p, va_list ap)
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);
}
......
......@@ -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
......
......@@ -410,6 +410,7 @@ mgt_run(int dflag, const char *T_arg)
setproctitle("Varnish-Mgr %s", heritage.name);
memset(&sac, 0, sizeof sac);
sac.sa_handler = SIG_IGN;
sac.sa_flags = SA_RESTART;
......
......@@ -317,6 +317,7 @@ smf_init(struct stevedore *parent, const char *spec)
return;
}
asprintf(&q, "%s/varnish.XXXXXX", p);
XXXAN(q);
sc->fd = mkstemp(q);
......@@ -331,6 +332,7 @@ smf_init(struct stevedore *parent, const char *spec)
XXXAN(sc->filename);
free(q);
smf_initfile(sc, size, 1);
free(p);
}
/*--------------------------------------------------------------------
......
......@@ -154,6 +154,7 @@ cli_readres(int fd, unsigned *status, char **ptr, double tmo)
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)
......
......@@ -95,18 +95,26 @@ static const char *vcc_default_vcl_b, *vcc_default_vcl_e;
/*--------------------------------------------------------------------*/
void *
TlAlloc(struct tokenlist *tl, unsigned len)
void
TlFree(struct tokenlist *tl, void *p)
{
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);
}
void *
TlAlloc(struct tokenlist *tl, unsigned len)
{
void *p;
p = calloc(len, 1);
assert(p != NULL);
TlFree(tl, p);
return (p);
}
......@@ -370,6 +378,8 @@ static void
vcc_destroy_source(struct source *sp)
{
if (sp->freeit != NULL)
free(sp->freeit);
free(sp->name);
free(sp);
}
......@@ -382,6 +392,7 @@ vcc_file_source(struct vsb *sb, const char *fn, int fd)
char *f;
int i;
struct stat st;
struct source *sp;
if (fd < 0) {
fd = open(fn, O_RDONLY);
......@@ -398,7 +409,9 @@ vcc_file_source(struct vsb *sb, const char *fn, int fd)
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 @@ static char *
vcc_DestroyTokenList(struct tokenlist *tl, char *ret)
{
struct membit *mb;
struct source *sp;
int i;
while (!TAILQ_EMPTY(&tl->membits)) {
......@@ -509,6 +523,11 @@ vcc_DestroyTokenList(struct tokenlist *tl, char *ret)
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 @@ VCC_Compile(struct vsb *sb, const char *b, const char *e)
if (sp == NULL)
return (NULL);
r = vcc_CompileSource(sb, sp);
vcc_destroy_source(sp);
return (r);
}
......@@ -664,7 +682,6 @@ VCC_CompileFile(struct vsb *sb, const char *fn, int fd)
if (sp == NULL)
return (NULL);
r = vcc_CompileSource(sb, sp);
vcc_destroy_source(sp);
return (r);
}
......
......@@ -45,6 +45,7 @@ struct source {
const char *b;
const char *e;
unsigned idx;
char *freeit;
};
struct token {
......@@ -153,6 +154,7 @@ void Fi(const struct tokenlist *tl, int indent, const char *fmt, ...);
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 */
......
......@@ -209,7 +209,7 @@ vcc_decstr(struct tokenlist *tl)
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 @@ vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e)
{
struct token *t;
t = calloc(sizeof *t, 1);
t = TlAlloc(tl, sizeof *t);
assert(t != NULL);
t->tok = tok;
t->b = b;
......
......@@ -64,10 +64,12 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
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);
}
......
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