Commit 956f64e2 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Be able to detect parse error during processing of backend Vary

headers, and do 503 on parse error.

Conflicts:
	bin/varnishd/cache.h
	bin/varnishd/cache/cache_req_fsm.c
	bin/varnishd/cache_vary.c
parent 4ba5ac11
......@@ -894,7 +894,7 @@ void RES_StreamEnd(struct sess *sp);
void RES_StreamPoll(const struct sess *sp);
/* cache_vary.c */
struct vsb *VRY_Create(const struct sess *sp, const struct http *hp);
int VRY_Create(const struct sess *sp, const struct http *hp, struct vsb **psb);
int VRY_Match(struct sess *sp, const uint8_t *vary);
void VRY_Validate(const uint8_t *vary);
......
This diff is collapsed.
......@@ -764,12 +764,21 @@ cnt_fetchbody(struct sess *sp)
/* Create Vary instructions */
if (sp->objcore != NULL) {
CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
vary = VRY_Create(sp, sp->wrk->beresp);
if (vary != NULL) {
varyl = VSB_len(vary);
assert(varyl > 0);
varyl = VRY_Create(sp, sp->wrk->beresp, &vary);
if (varyl > 0) {
AN(vary);
assert(varyl == VSB_len(vary));
l += varyl;
}
} else if (varyl < 0) {
/* Vary parse error */
AZ(vary);
sp->err_code = 503;
sp->step = STP_ERROR;
VDI_CloseFd(sp);
return (0);
} else
/* No vary */
AZ(vary);
}
/*
......
......@@ -61,16 +61,29 @@
#include "vend.h"
#include "vct.h"
struct vsb *
VRY_Create(const struct sess *sp, const struct http *hp)
/**********************************************************************
* Create a Vary matching string from a Vary header
*
* Return value:
* <0: Parse error
* 0: No Vary header on object
* >0: Length of Vary matching string in *psb
*/
int
VRY_Create(const struct sess *sp, const struct http *hp, struct vsb **psb)
{
char *v, *p, *q, *h, *e;
struct vsb *sb, *sbh;
int l;
int error = 0;
AN(psb);
AZ(*psb);
/* No Vary: header, no worries */
if (!http_GetHdr(hp, H_Vary, &v))
return (NULL);
return (0);
/* For vary matching string */
sb = VSB_new_auto();
......@@ -124,12 +137,20 @@ VRY_Create(const struct sess *sp, const struct http *hp)
xxxassert(*q == ',');
p = q;
}
if (error) {
VSB_delete(sbh);
VSB_delete(sb);
return (-1);
}
/* Terminate vary matching string */
VSB_printf(sb, "%c%c%c", 0xff, 0xff, 0);
VSB_delete(sbh);
AZ(VSB_finish(sb));
return(sb);
*psb = sb;
return (VSB_len(sb));
}
/*
......
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