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

[or-cvs] Backport: Fix assertion-trigger bug found by sjmurdoch



Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv7671/src/common

Modified Files:
      Tag: tor-0_1_0-patches
	util.c 
Log Message:
Backport: Fix assertion-trigger bug found by sjmurdoch

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.208
retrieving revision 1.208.2.1
diff -u -p -d -r1.208 -r1.208.2.1
--- util.c	6 Apr 2005 19:07:35 -0000	1.208
+++ util.c	1 Jan 2006 23:13:35 -0000	1.208.2.1
@@ -580,9 +580,10 @@ tor_timegm(struct tm *tm) {
   unsigned long year, days, hours, minutes;
   int i;
   year = tm->tm_year + 1900;
-  tor_assert(year >= 1970);
-  tor_assert(tm->tm_mon >= 0);
-  tor_assert(tm->tm_mon <= 11);
+  if (year < 1970 || tm->tm_mon < 0 || tm->tm_mon > 11) {
+    log_fn(LOG_WARN, "Out-of-range argument to tor_timegm");
+    return -1;
+  }
   days = 365 * (year-1970) + n_leapdays(1970,year);
   for (i = 0; i < tm->tm_mon; ++i)
     days += days_per_month[i];
@@ -644,9 +645,14 @@ int parse_rfc1123_time(const char *buf, 
     log_fn(LOG_WARN, "Got invalid RFC1123 time \"%s\"", buf);
     return -1;
   }
-
   tm.tm_mon = m;
+
+  if (tm.tm_year < 1970) {
+    log_fn(LOG_WARN, "Got invalid RFC1123 time \"%s\". (Before 1970)", buf);
+    return -1;
+  }
   tm.tm_year -= 1900;
+
   *t = tor_timegm(&tm);
   return 0;
 }
@@ -684,6 +690,10 @@ int parse_iso_time(const char *cp, time_
   st_tm.tm_min = minute;
   st_tm.tm_sec = second;
 #endif
+  if (st_tm.tm_year < 70) {
+    log_fn(LOG_WARN,"Got invalid ISO time \"%s\". (Before 1970)", cp);
+    return -1;
+  }
   *t = tor_timegm(&st_tm);
   return 0;
 }