Commit d0b0956f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Do correct LostHeader processing on WS_Alloc() failure


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1636 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 96c2b817
...@@ -801,6 +801,7 @@ void ...@@ -801,6 +801,7 @@ void
http_CopyHome(struct worker *w, int fd, struct http *hp) http_CopyHome(struct worker *w, int fd, struct http *hp)
{ {
unsigned u, l; unsigned u, l;
enum httptag htt;
char *p; char *p;
for (u = 0; u < hp->nhd; u++) { for (u = 0; u < hp->nhd; u++) {
...@@ -808,25 +809,34 @@ http_CopyHome(struct worker *w, int fd, struct http *hp) ...@@ -808,25 +809,34 @@ http_CopyHome(struct worker *w, int fd, struct http *hp)
continue; continue;
switch (u) { switch (u) {
case HTTP_HDR_PROTO: case HTTP_HDR_PROTO:
WSLH(w, HTTP_T_Protocol, fd, hp, u); htt = HTTP_T_Protocol;
break; break;
case HTTP_HDR_STATUS: case HTTP_HDR_STATUS:
WSLH(w, HTTP_T_Status, fd, hp, u); htt = HTTP_T_Status;
break; break;
case HTTP_HDR_RESPONSE: case HTTP_HDR_RESPONSE:
WSLH(w, HTTP_T_Response, fd, hp, u); htt = HTTP_T_Response;
break; break;
default: default:
WSLH(w, HTTP_T_Header, fd, hp, u); htt = HTTP_T_Header;
break; break;
} }
if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e) if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e) {
WSLH(w, htt, fd, hp, u);
continue; continue;
}
l = hp->hd[u].e - hp->hd[u].b; l = hp->hd[u].e - hp->hd[u].b;
p = WS_Alloc(hp->ws, l + 1); p = WS_Alloc(hp->ws, l + 1);
if (p != NULL) {
WSLH(w, htt, fd, hp, u);
memcpy(p, hp->hd[u].b, l + 1); memcpy(p, hp->hd[u].b, l + 1);
hp->hd[u].b = p; hp->hd[u].b = p;
hp->hd[u].e = p + l; hp->hd[u].e = p + l;
} else {
WSLH(w, HTTP_T_LostHeader, fd, hp, u);
hp->hd[u].b = NULL;
hp->hd[u].e = NULL;
}
} }
} }
...@@ -860,7 +870,7 @@ http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr) ...@@ -860,7 +870,7 @@ http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void static void
http_PutField(struct http *to, int field, const char *string) http_PutField(struct worker *w, int fd, struct http *to, int field, const char *string)
{ {
const char *e; const char *e;
char *p; char *p;
...@@ -870,18 +880,22 @@ http_PutField(struct http *to, int field, const char *string) ...@@ -870,18 +880,22 @@ http_PutField(struct http *to, int field, const char *string)
e = strchr(string, '\0'); e = strchr(string, '\0');
l = (e - string); l = (e - string);
p = WS_Alloc(to->ws, l + 1); p = WS_Alloc(to->ws, l + 1);
if (p == NULL) {
WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", string);
to->hd[field].b = NULL;
to->hd[field].e = NULL;
} else {
memcpy(p, string, l + 1); memcpy(p, string, l + 1);
to->hd[field].b = p; to->hd[field].b = p;
to->hd[field].e = p + l; to->hd[field].e = p + l;
}
} }
void void
http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol) http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol)
{ {
(void)w; /* should be used to report losthdr */ http_PutField(w, fd, to, HTTP_HDR_PROTO, protocol);
(void)fd; /* should be used to report losthdr */
http_PutField(to, HTTP_HDR_PROTO, protocol);
} }
void void
...@@ -889,20 +903,16 @@ http_PutStatus(struct worker *w, int fd, struct http *to, int status) ...@@ -889,20 +903,16 @@ http_PutStatus(struct worker *w, int fd, struct http *to, int status)
{ {
char stat[4]; char stat[4];
(void)w; /* should be used to report losthdr */
(void)fd; /* should be used to report losthdr */
assert(status >= 0 && status <= 999); assert(status >= 0 && status <= 999);
sprintf(stat, "%d", status); sprintf(stat, "%d", status);
http_PutField(to, HTTP_HDR_STATUS, stat); http_PutField(w, fd, to, HTTP_HDR_STATUS, stat);
} }
void void
http_PutResponse(struct worker *w, int fd, struct http *to, const char *response) http_PutResponse(struct worker *w, int fd, struct http *to, const char *response)
{ {
(void)w; /* should be used to report losthdr */ http_PutField(w, fd, to, HTTP_HDR_RESPONSE, response);
(void)fd; /* should be used to report losthdr */
http_PutField(to, HTTP_HDR_RESPONSE, response);
} }
void void
......
...@@ -89,7 +89,8 @@ WS_Alloc(struct ws *ws, unsigned bytes) ...@@ -89,7 +89,8 @@ WS_Alloc(struct ws *ws, unsigned bytes)
WS_Assert(ws); WS_Assert(ws);
assert(ws->r == NULL); assert(ws->r == NULL);
xxxassert(ws->f + bytes <= ws->e); if (ws->f + bytes > ws->e)
return(NULL);
r = ws->f; r = ws->f;
ws->f += bytes; ws->f += bytes;
return (r); return (r);
......
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