Permalink
Browse files

Ignore fields with invalid C-C values

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 Dec 27, 2018
1 parent 42f3ee8 commit 2433f397be91ac02a4b16ef2dc651a002c1f6e17
Showing with 18 additions and 11 deletions.
  1. +18 −11 bin/varnishd/cache/cache_rfc2616.c
@@ -34,6 +34,7 @@
#include "cache_varnishd.h"

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

/*--------------------------------------------------------------------
* TTL and Age calculation in Varnish
@@ -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)
@@ -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;
}
@@ -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,

0 comments on commit 2433f39

Please sign in to comment.