[tor-commits] [tor/release-0.2.2] Remove more dubiosity in struct tm handling. related to bug5346

arma at torproject.org arma at torproject.org
Fri May 18 20:50:13 UTC 2012


commit 801923ac2112d1a54eaf4126800724bea90055eb
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Mar 9 10:24:40 2012 -0500

    Remove more dubiosity in struct tm handling. related to bug5346
---
 changes/bug5346   |    2 ++
 src/common/util.c |   15 ++++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/changes/bug5346 b/changes/bug5346
index 490eb35..3d21f90 100644
--- a/changes/bug5346
+++ b/changes/bug5346
@@ -3,4 +3,6 @@
       Without this patch, If-Modified-Since would behave
       incorrectly. Fix for bug 5346; bugfix on 0.2.0.2-alpha. Patch from
       Esteban Manchado Velázques.
+    - Reject out-of-range times like 23:59:61. Fix for bug 5346;
+      bugfix on 0.0.8pre3.
 
diff --git a/src/common/util.c b/src/common/util.c
index c44fe60..5fa0896 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1268,7 +1268,7 @@ format_rfc1123_time(char *buf, time_t t)
   tor_assert(tm.tm_wday >= 0);
   tor_assert(tm.tm_wday <= 6);
   memcpy(buf, WEEKDAY_NAMES[tm.tm_wday], 3);
-  tor_assert(tm.tm_wday >= 0);
+  tor_assert(tm.tm_mon >= 0);
   tor_assert(tm.tm_mon <= 11);
   memcpy(buf+8, MONTH_NAMES[tm.tm_mon], 3);
 }
@@ -1298,7 +1298,8 @@ parse_rfc1123_time(const char *buf, time_t *t)
     tor_free(esc);
     return -1;
   }
-  if (tm_mday > 31 || tm_hour > 23 || tm_min > 59 || tm_sec > 61) {
+  if (tm_mday < 1 || tm_mday > 31 || tm_hour > 23 || tm_min > 59 ||
+      tm_sec > 60) {
     char *esc = esc_for_log(buf);
     log_warn(LD_GENERAL, "Got invalid RFC1123 time %s", esc);
     tor_free(esc);
@@ -1368,7 +1369,7 @@ int
 parse_iso_time(const char *cp, time_t *t)
 {
   struct tm st_tm;
-  unsigned int year=0, month=0, day=0, hour=100, minute=100, second=100;
+  unsigned int year=0, month=0, day=0, hour=0, minute=0, second=0;
   if (tor_sscanf(cp, "%u-%2u-%2u %2u:%2u:%2u", &year, &month,
                 &day, &hour, &minute, &second) < 6) {
     char *esc = esc_for_log(cp);
@@ -1377,7 +1378,7 @@ parse_iso_time(const char *cp, time_t *t)
     return -1;
   }
   if (year < 1970 || month < 1 || month > 12 || day < 1 || day > 31 ||
-          hour > 23 || minute > 59 || second > 61) {
+          hour > 23 || minute > 59 || second > 60) {
     char *esc = esc_for_log(cp);
     log_warn(LD_GENERAL, "ISO time %s was nonsensical", esc);
     tor_free(esc);
@@ -1457,11 +1458,11 @@ parse_http_time(const char *date, struct tm *tm)
   }
 
   if (tm->tm_year < 0 ||
-      tm->tm_mon < 1  || tm->tm_mon > 12 ||
-      tm->tm_mday < 0 || tm->tm_mday > 31 ||
+      tm->tm_mon < 0  || tm->tm_mon > 11 ||
+      tm->tm_mday < 1 || tm->tm_mday > 31 ||
       tm->tm_hour < 0 || tm->tm_hour > 23 ||
       tm->tm_min < 0  || tm->tm_min > 59 ||
-      tm->tm_sec < 0  || tm->tm_sec > 61)
+      tm->tm_sec < 0  || tm->tm_sec > 60)
     return -1; /* Out of range, or bad month. */
 
   return 0;





More information about the tor-commits mailing list