diff options
author | Esteban Manchado Velázquez <emanchado@demiurgo.org> | 2012-02-20 17:40:37 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-05-16 12:14:48 -0400 |
commit | d0d9c3d71e1fb88557d684c59cf8a920712b16f1 (patch) | |
tree | 78b18ac9779556d974963b5db11d0488cfcc5689 /src/common | |
parent | 3ed4c5dc05a1954a8c68d0f7e9fb802f3155d308 (diff) | |
download | tor-d0d9c3d71e1fb88557d684c59cf8a920712b16f1.tar tor-d0d9c3d71e1fb88557d684c59cf8a920712b16f1.tar.gz |
Fix parse_http_time and add tests
* It seems parse_http_time wasn't parsing correctly any date with commas (RFCs
1123 and 850). Fix that.
* It seems parse_http_time was reporting the wrong month (they start at 0, not
1). Fix that.
* Add some tests for parse_http_time, covering all three formats.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common/util.c b/src/common/util.c index 7d2fc4dea..391b02f34 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1416,13 +1416,13 @@ parse_http_time(const char *date, struct tm *tm) /* First, try RFC1123 or RFC850 format: skip the weekday. */ if ((cp = strchr(date, ','))) { - ++cp; - if (tor_sscanf(date, "%2u %3s %4u %2u:%2u:%2u GMT", + cp += 2; + if (tor_sscanf(cp, "%2u %3s %4u %2u:%2u:%2u GMT", &tm_mday, month, &tm_year, &tm_hour, &tm_min, &tm_sec) == 6) { /* rfc1123-date */ tm_year -= 1900; - } else if (tor_sscanf(date, "%2u-%3s-%2u %2u:%2u:%2u GMT", + } else if (tor_sscanf(cp, "%2u-%3s-%2u %2u:%2u:%2u GMT", &tm_mday, month, &tm_year, &tm_hour, &tm_min, &tm_sec) == 6) { /* rfc850-date */ @@ -1449,7 +1449,7 @@ parse_http_time(const char *date, struct tm *tm) /* Okay, now decode the month. */ for (i = 0; i < 12; ++i) { if (!strcasecmp(MONTH_NAMES[i], month)) { - tm->tm_mon = i+1; + tm->tm_mon = i; } } |