From 4a80f762b1f9c39459dc3d3b77650e6d2ace6766 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 7 Jul 2006 06:29:23 +0000 Subject: [PATCH] Dump our buffer as Debug if we have HTTP header trouble. Issue 400 for HTTP header buffer overflow. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@366 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 2 +- varnish-cache/bin/varnishd/cache_http.c | 31 +++++++++++++++++++------ varnish-cache/bin/varnishd/cache_pool.c | 9 ++++--- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index e3083ca9..3c60a06b 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -169,7 +169,7 @@ void HSH_Deref(struct object *o); void HSH_Init(void); /* cache_http.c */ -typedef void http_callback_f(void *, int good); +typedef void http_callback_f(void *, int bad); struct http; struct http *http_New(void); void http_Delete(struct http *hp); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 795d4c12..2316ac86 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -226,21 +226,27 @@ http_Dissect(struct http *hp, int fd, int rr) /* Next find the URI */ while (isspace(*p) && *p != '\n') p++; - if (*p == '\n') + if (*p == '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); return (400); + } hp->url = p; while (!isspace(*p)) p++; VSLR(SLT_URL, fd, hp->url, p); - if (*p == '\n') + if (*p == '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); return (400); + } *p++ = '\0'; /* Finally, look for protocol */ while (isspace(*p) && *p != '\n') p++; - if (*p == '\n') + if (*p == '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); return (400); + } hp->proto = p; while (!isspace(*p)) p++; @@ -249,8 +255,10 @@ http_Dissect(struct http *hp, int fd, int rr) *p++ = '\0'; while (isspace(*p) && *p != '\n') p++; - if (*p != '\n') + if (*p != '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); return (400); + } *p++ = '\0'; } else { /* First, protocol */ @@ -354,6 +362,14 @@ http_read_f(int fd, short event, void *arg) int i; l = hp->e - hp->v; + if (l <= 1) { + VSLR(SLT_Debug, fd, hp->s, hp->v); + hp->t = NULL; + event_del(&hp->ev); + if (hp->callback != NULL) + hp->callback(hp->arg, 1); + return; + } assert(l > 1); errno = 0; i = read(fd, hp->v, l - 1); @@ -366,10 +382,11 @@ http_read_f(int fd, short event, void *arg) VSL(SLT_HttpError, fd, "Received nothing"); else VSL(SLT_HttpError, fd, "Received errno %d", errno); + VSLR(SLT_Debug, fd, hp->s, hp->v); hp->t = NULL; event_del(&hp->ev); if (hp->callback != NULL) - hp->callback(hp->arg, 0); + hp->callback(hp->arg, 2); return; } @@ -381,7 +398,7 @@ http_read_f(int fd, short event, void *arg) assert(hp->t != NULL); event_del(&hp->ev); if (hp->callback != NULL) - hp->callback(hp->arg, 1); + hp->callback(hp->arg, 0); } /*--------------------------------------------------------------------*/ @@ -403,7 +420,7 @@ http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *f hp->t = hp->s; if (http_header_complete(hp)) { assert(func != NULL); - func(arg, 1); + func(arg, 0); return; } } else { diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 4f3fdf94..323ab3b1 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -135,12 +135,15 @@ out: } void -DealWithSession(void *arg, int good) +DealWithSession(void *arg, int bad) { struct sess *sp = arg; - if (!good) { - vca_close_session(sp, "no request"); + if (bad) { + if (bad == 1) + vca_close_session(sp, "overflow"); + else + vca_close_session(sp, "no request"); vca_return_session(sp); return; } -- 2.39.5