[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/maint-0.2.2] Fix month check in parse_http_time, add test



commit 679aa93e23f2c7f2e9c195f08834a7fc8c8d8b29
Author: Sebastian Hahn <sebastian@xxxxxxxxxxxxxx>
Date:   Fri Mar 9 15:40:44 2012 +0100

    Fix month check in parse_http_time, add test
---
 src/common/util.c    |    2 ++
 src/test/test_util.c |    4 ++++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 5fa0896..a03a576 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1451,6 +1451,8 @@ parse_http_time(const char *date, struct tm *tm)
 
   month[3] = '\0';
   /* Okay, now decode the month. */
+  /* set tm->tm_mon to dummy value so the check below fails. */
+  tm->tm_mon = -1;
   for (i = 0; i < 12; ++i) {
     if (!strcasecmp(MONTH_NAMES[i], month)) {
       tm->tm_mon = i;
diff --git a/src/test/test_util.c b/src/test/test_util.c
index e239326..cc0181c 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -121,6 +121,10 @@ test_util_parse_http_time(void *arg)
   test_eq((time_t)775961302UL, tor_timegm(&a_time));
   test_eq(0, parse_http_time("Mie Aug 4 0:48:22 1994", &a_time));
   test_eq((time_t)775961302UL, tor_timegm(&a_time));
+  test_eq(0, parse_http_time("Sun, 1 Jan 2012 00:00:00 GMT", &a_time));
+  test_eq((time_t)1325376000UL, tor_timegm(&a_time));
+  test_eq(0, parse_http_time("Mon, 31 Dec 2012 00:00:00 GMT", &a_time));
+  test_eq((time_t)1356912000UL, tor_timegm(&a_time));
   test_eq(-1, parse_http_time("2004-08-zz 99-99x99 GMT", &a_time));
   test_eq(-1, parse_http_time("2011-03-32 00:00:00 GMT", &a_time));
   test_eq(-1, parse_http_time("2011-03-30 24:00:00 GMT", &a_time));



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits