Skip to content

Commit

Permalink
Ignore fields with invalid C-C values
Browse files Browse the repository at this point in the history
Should address "HTTP cache must not reuse a response with an invalid
Cache-Control: max-age (trailing alpha)" from https://cache-tests.fyi.
  • Loading branch information
fgsch committed Jan 3, 2019
1 parent 42f3ee8 commit 2433f39
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions bin/varnishd/cache/cache_rfc2616.c
Expand Up @@ -34,6 +34,7 @@
#include "cache_varnishd.h"

#include "vtim.h"
#include "vct.h"

/*--------------------------------------------------------------------
* TTL and Age calculation in Varnish
Expand Down Expand Up @@ -61,6 +62,21 @@
*
*/

static inline int
rfc2616_time(const char *p)
{
char *ep;
int val;
if (*p == '-')
return (0);
val = strtoul(p, &ep, 10);
for (; *ep != '\0' && vct_issp(*ep); ep++)
continue;
if (*ep == '\0' || *ep == ',')
return (val);
return (0);
}

void
RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin,
float *ttl, float *grace, float *keep)
Expand Down Expand Up @@ -140,12 +156,7 @@ RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin,
if ((http_GetHdrField(hp, H_Cache_Control, "s-maxage", &p) ||
http_GetHdrField(hp, H_Cache_Control, "max-age", &p)) &&
p != NULL) {

if (*p == '-')
max_age = 0;
else
max_age = strtoul(p, NULL, 0);

max_age = rfc2616_time(p);
*ttl = max_age;
break;
}
Expand Down Expand Up @@ -190,11 +201,7 @@ RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin,
*/
if (*ttl >= 0 && http_GetHdrField(hp, H_Cache_Control,
"stale-while-revalidate", &p) && p != NULL) {

if (*p == '-')
*grace = 0;
else
*grace = strtoul(p, NULL, 0);
*grace = rfc2616_time(p);
}

VSLb(bo->vsl, SLT_TTL,
Expand Down

0 comments on commit 2433f39

Please sign in to comment.