Mailing List Archive

[6.0] cd7ec513b Fixup private rfc2616_time function
commit cd7ec513b38380a054a23475ca7900316c99360b
Author: Martin Blix Grydeland <martin@varnish-software.com>
Date: Tue Feb 25 15:22:36 2020 +0100

Fixup private rfc2616_time function

Change the return value to unsigned, to match with the expected data type
where it is used.

Handle very large numbers consistently. Currently it was converting from
unsigned long to int, which would throw away the most significant
bits. Now overly large integers will be capped at UINT_MAX.

Implement the "allow and ignore decimal point" behaviour that the Age
header parsing incorporated in rfc2616_time(). This way we will allow a
decimal points also in max-age and stale-while-revalidate parsing of
Cache-Control directives.

diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index e78204782..79317394e 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -62,17 +62,22 @@
*
*/

-static inline int
+static inline unsigned
rfc2616_time(const char *p)
{
char *ep;
- int val;
+ unsigned long val;
if (*p == '-')
return (0);
val = strtoul(p, &ep, 10);
- for (; *ep != '\0' && vct_issp(*ep); ep++)
- continue;
- if (*ep == '\0' || *ep == ',')
+ if (val > UINT_MAX)
+ return (UINT_MAX);
+ while (vct_issp(*ep))
+ ep++;
+ /* We accept ',' as an end character because we may be parsing a
+ * multi-element Cache-Control part. We accept '.' to be future
+ * compatble with fractional seconds. */
+ if (*ep == '\0' || *ep == ',' || *ep == '.')
return (val);
return (0);
}
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit