Commit aaaf7b38 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Nils Goroll

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.
parent 55bd09a4
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment