From eafc46f1506f3261543070bf86ed61a1eabd0b87 Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 21 Jun 2008 18:55:13 +0000 Subject: [PATCH] NB: some of this commit sneaked into #2757 Fix http_GetHdrField() to use the correct RFC2616 syntax for tokens and separators. Fixes ticket #255. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2758 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_http.c | 7 +++++-- varnish-cache/bin/varnishd/rfc2616.c | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 5826023f..8985b0b5 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -269,22 +269,25 @@ http_GetHdrField(const struct http *hp, const char *hdr, const char *field, char h++; continue; } + /* Check for substrings before memcmp() */ if ((h + fl == e || vct_issepctl(h[fl])) && !memcmp(h, field, fl)) { /* got it */ h += fl; if (ptr != NULL) { - while (vct_issp(*h)) + /* Skip whitespace, looking for '=' */ + while (*h && vct_issp(*h)) h++; if (*h == '=') { h++; - while (vct_issp(*h)) + while (*h && vct_issp(*h)) h++; *ptr = h; } } return (1); } + /* Skip token */ while (*h && !vct_issepctl(*h)) h++; } diff --git a/varnish-cache/bin/varnishd/rfc2616.c b/varnish-cache/bin/varnishd/rfc2616.c index c153c21d..52762aa9 100644 --- a/varnish-cache/bin/varnishd/rfc2616.c +++ b/varnish-cache/bin/varnishd/rfc2616.c @@ -110,9 +110,9 @@ RFC2616_Ttl(const struct sess *sp, const struct http *hp, struct object *obj) retirement_age = INT_MAX; u1 = u2 = 0; - if (http_GetHdrField(hp, H_Cache_Control, "s-maxage", &p) || - http_GetHdrField(hp, H_Cache_Control, "max-age", &p)) { - AN(p); + if ((http_GetHdrField(hp, H_Cache_Control, "s-maxage", &p) || + http_GetHdrField(hp, H_Cache_Control, "max-age", &p)) && + p != NULL { u1 = strtoul(p, NULL, 0); u2 = 0; if (http_GetHdr(hp, H_Age, &p)) { -- 2.39.5