[master] aaaf7b383 Fixup private rfc2616_time function

Nils Goroll nils.goroll at uplex.de
Wed Feb 26 13:08:09 UTC 2020


commit aaaf7b383339b18f368935ff3fd38a6575c15666
Author: Martin Blix Grydeland <martin at 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 14e655c49..22263a7bf 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -64,17 +64,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);
 }


More information about the varnish-commit mailing list