Commit c394dfb7 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.
parent d1bbd0b3
...@@ -1003,7 +1003,7 @@ void RES_BuildHttp(struct req *); ...@@ -1003,7 +1003,7 @@ void RES_BuildHttp(struct req *);
void RES_WriteObj(struct req *); void RES_WriteObj(struct req *);
/* cache_vary.c */ /* cache_vary.c */
struct vsb *VRY_Create(struct req *sp, const struct http *hp); int VRY_Create(struct req *req, const struct http *hp, struct vsb **psb);
int VRY_Match(struct req *, const uint8_t *vary); int VRY_Match(struct req *, const uint8_t *vary);
void VRY_Validate(const uint8_t *vary); void VRY_Validate(const uint8_t *vary);
void VRY_Prep(struct req *); void VRY_Prep(struct req *);
......
...@@ -572,12 +572,24 @@ cnt_fetchbody(struct worker *wrk, struct req *req) ...@@ -572,12 +572,24 @@ cnt_fetchbody(struct worker *wrk, struct req *req)
/* Create Vary instructions */ /* Create Vary instructions */
if (req->objcore->objhead != NULL) { if (req->objcore->objhead != NULL) {
vary = VRY_Create(req, bo->beresp); varyl = VRY_Create(req, bo->beresp, &vary);
if (vary != NULL) { if (varyl > 0) {
varyl = VSB_len(vary); AN(vary);
assert(varyl > 0); assert(varyl == VSB_len(vary));
l += varyl; l += varyl;
} } else if (varyl < 0) {
/* Vary parse error */
AZ(vary);
req->err_code = 503;
req->req_step = R_STP_ERROR;
AZ(HSH_Deref(&wrk->stats, req->objcore, NULL));
req->objcore = NULL;
VDI_CloseFd(&bo->vbc);
VBO_DerefBusyObj(wrk, &req->busyobj);
return (REQ_FSM_MORE);
} else
/* No vary */
AZ(vary);
} }
/* /*
......
...@@ -61,16 +61,29 @@ ...@@ -61,16 +61,29 @@
#include "vct.h" #include "vct.h"
#include "vend.h" #include "vend.h"
struct vsb * /**********************************************************************
VRY_Create(struct req *req, 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(struct req *req, const struct http *hp, struct vsb **psb)
{ {
char *v, *p, *q, *h, *e; char *v, *p, *q, *h, *e;
struct vsb *sb, *sbh; struct vsb *sb, *sbh;
unsigned l; unsigned l;
int error = 0;
AN(psb);
AZ(*psb);
/* No Vary: header, no worries */ /* No Vary: header, no worries */
if (!http_GetHdr(hp, H_Vary, &v)) if (!http_GetHdr(hp, H_Vary, &v))
return (NULL); return (0);
/* For vary matching string */ /* For vary matching string */
sb = VSB_new_auto(); sb = VSB_new_auto();
...@@ -125,12 +138,20 @@ VRY_Create(struct req *req, const struct http *hp) ...@@ -125,12 +138,20 @@ VRY_Create(struct req *req, const struct http *hp)
xxxassert(*q == ','); xxxassert(*q == ',');
p = q; p = q;
} }
if (error) {
VSB_delete(sbh);
VSB_delete(sb);
return (-1);
}
/* Terminate vary matching string */ /* Terminate vary matching string */
VSB_printf(sb, "%c%c%c", 0xff, 0xff, 0); VSB_printf(sb, "%c%c%c", 0xff, 0xff, 0);
VSB_delete(sbh); VSB_delete(sbh);
AZ(VSB_finish(sb)); 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