summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-07-18 23:45:40 -0400
committerNick Mathewson <nickm@torproject.org>2015-01-07 10:05:55 -0500
commit7984fc153112baa5c370215f2205025a7648d7b4 (patch)
tree75aefda08013f19fb2345d27d4f65890afb4299c /src/common
parent9b11dc36179e48bd39e57a9f3e0e26a25f50adfa (diff)
downloadtor-7984fc153112baa5c370215f2205025a7648d7b4.tar.gz
tor-7984fc153112baa5c370215f2205025a7648d7b4.zip
Stop accepting milliseconds in various directory contexts
Have clients and authorities both have new behavior, since the fix for bug 11243 has gone in. But make clients still accept accept old bogus HSDir descriptors, to avoid fingerprinting trickery. Fixes bug 9286.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c23
-rw-r--r--src/common/util.h1
2 files changed, 19 insertions, 5 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 50097dac93..481f96bb0f 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1656,15 +1656,18 @@ format_iso_time_nospace_usec(char *buf, const struct timeval *tv)
/** Given an ISO-formatted UTC time value (after the epoch) in <b>cp</b>,
* parse it and store its value in *<b>t</b>. Return 0 on success, -1 on
- * failure. Ignore extraneous stuff in <b>cp</b> separated by whitespace from
- * the end of the time string. */
+ * failure. Ignore extraneous stuff in <b>cp</b> after the end of the time
+ * string, unless <b>strict</b> is set. */
int
-parse_iso_time(const char *cp, time_t *t)
+parse_iso_time_(const char *cp, time_t *t, int strict)
{
struct tm st_tm;
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) {
+ int n_fields;
+ char extra_char;
+ n_fields = tor_sscanf(cp, "%u-%2u-%2u %2u:%2u:%2u%c", &year, &month,
+ &day, &hour, &minute, &second, &extra_char);
+ if (strict ? (n_fields != 6) : (n_fields < 6)) {
char *esc = esc_for_log(cp);
log_warn(LD_GENERAL, "ISO time %s was unparseable", esc);
tor_free(esc);
@@ -1693,6 +1696,16 @@ parse_iso_time(const char *cp, time_t *t)
return tor_timegm(&st_tm, t);
}
+/** Given an ISO-formatted UTC time value (after the epoch) in <b>cp</b>,
+ * parse it and store its value in *<b>t</b>. Return 0 on success, -1 on
+ * failure. Reject the string if any characters are present after the time.
+ */
+int
+parse_iso_time(const char *cp, time_t *t)
+{
+ return parse_iso_time_(cp, t, 1);
+}
+
/** Given a <b>date</b> in one of the three formats allowed by HTTP (ugh),
* parse it into <b>tm</b>. Return 0 on success, negative on failure. */
int
diff --git a/src/common/util.h b/src/common/util.h
index 921dd79da0..a3a79a928d 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -270,6 +270,7 @@ void format_local_iso_time(char *buf, time_t t);
void format_iso_time(char *buf, time_t t);
void format_iso_time_nospace(char *buf, time_t t);
void format_iso_time_nospace_usec(char *buf, const struct timeval *tv);
+int parse_iso_time_(const char *cp, time_t *t, int strict);
int parse_iso_time(const char *buf, time_t *t);
int parse_http_time(const char *buf, struct tm *tm);
int format_time_interval(char *out, size_t out_len, long interval);