[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Fix some bugs in parse_time
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv16530/src/or
Modified Files:
routerlist.c
Log Message:
Fix some bugs in parse_time
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- routerlist.c 9 Mar 2004 22:09:13 -0000 1.35
+++ routerlist.c 9 Mar 2004 22:17:35 -0000 1.36
@@ -541,22 +541,22 @@
== ADDR_POLICY_REJECTED;
}
-static time_t parse_time(const char *cp)
+static int parse_time(const char *cp, time_t *t)
{
struct tm st_tm;
#ifdef HAVE_STRPTIME
if (!strptime(cp, "%Y-%m-%d %H:%M:%S", &st_tm)) {
- log_fn(LOG_WARN, "Published time was unparseable"); return 0;
+ log_fn(LOG_WARN, "Published time was unparseable"); return -1;
}
#else
unsigned int year=0, month=0, day=0, hour=100, minute=100, second=100;
- if (scanf("%u-%u-%u %u:%u:%u", cp, &year, &month,
+ if (sscanf(cp, "%u-%u-%u %u:%u:%u", &year, &month,
&day, &hour, &minute, &second) < 6) {
- log_fn(LOG_WARN, "Published time was unparseable"); return 0;
+ log_fn(LOG_WARN, "Published time was unparseable"); return -1;
}
- if (year < 2000 || month < 1 || month > 12 || day < 1 || day > 31 ||
+ if (year < 1970 || month < 1 || month > 12 || day < 1 || day > 31 ||
hour > 24 || minute > 61 || second > 62) {
- log_fn(LOG_WARN, "Published time was nonsensical"); return 0;
+ log_fn(LOG_WARN, "Published time was nonsensical"); return -1;
}
st_tm.tm_year = year;
st_tm.tm_mon = month;
@@ -565,8 +565,8 @@
st_tm.tm_min = minute;
st_tm.tm_sec = second;
#endif
- return tor_timegm(&st_tm);
-
+ *t = tor_timegm(&st_tm);
+ return 0;
}
@@ -632,7 +632,7 @@
}
assert(tok->n_args == 1);
- if (!(published_on = parse_time(tok->args[0]))) {
+ if (parse_time(tok->args[0], &published_on) < 0) {
goto err;
}
@@ -902,7 +902,7 @@
log_fn(LOG_WARN, "Missing published time"); goto err;
}
assert(tok->n_args == 1);
- if (!(router->published_on = parse_time(tok->args[0])))
+ if (parse_time(tok->args[0], &router->published_on) < 0)
goto err;
if (!(tok = find_first_by_keyword(tokens, K_ONION_KEY))) {