aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/channeltls.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-08-06 11:18:40 -0400
committerNick Mathewson <nickm@torproject.org>2019-08-06 11:18:40 -0400
commit79569d86b36ae1a89b5656bf8356247574b32e95 (patch)
tree9d58605717a7156ed0ebdf699e6b90312e36436a /src/core/or/channeltls.c
parent2a42d6be2707bbc28ad9d68055799297d1d07daf (diff)
parentbc9492a938f0bc2ee8dfb6f94f0f8d81f16b9575 (diff)
downloadtor-79569d86b36ae1a89b5656bf8356247574b32e95.tar.gz
tor-79569d86b36ae1a89b5656bf8356247574b32e95.zip
Merge branch 'ticket31343_035' into ticket31343_040
Diffstat (limited to 'src/core/or/channeltls.c')
-rw-r--r--src/core/or/channeltls.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/core/or/channeltls.c b/src/core/or/channeltls.c
index f552b20770..5a00a9e00f 100644
--- a/src/core/or/channeltls.c
+++ b/src/core/or/channeltls.c
@@ -1664,7 +1664,19 @@ tor_addr_from_netinfo_addr(tor_addr_t *tor_addr,
}
/**
- * Process a 'netinfo' cell.
+ * Helper: compute the absolute value of a time_t.
+ *
+ * (we need this because labs() doesn't always work for time_t, since
+ * long can be shorter than time_t.)
+ */
+static inline time_t
+time_abs(time_t val)
+{
+ return (val < 0) ? -val : val;
+}
+
+/**
+ * Process a 'netinfo' cell
*
* This function is called to handle an incoming NETINFO cell; read and act
* on its contents, and set the connection state to "open".
@@ -1679,7 +1691,7 @@ channel_tls_process_netinfo_cell(cell_t *cell, channel_tls_t *chan)
time_t now = time(NULL);
const routerinfo_t *me = router_get_my_routerinfo();
- long apparent_skew = 0;
+ time_t apparent_skew = 0;
tor_addr_t my_apparent_addr = TOR_ADDR_NULL;
int started_here = 0;
const char *identity_digest = NULL;
@@ -1765,7 +1777,7 @@ channel_tls_process_netinfo_cell(cell_t *cell, channel_tls_t *chan)
my_addr_type = netinfo_addr_get_addr_type(my_addr);
my_addr_len = netinfo_addr_get_len(my_addr);
- if (labs(now - chan->conn->handshake_state->sent_versions_at) < 180) {
+ if ((now - chan->conn->handshake_state->sent_versions_at) < 180) {
apparent_skew = now - timestamp;
}
/* We used to check:
@@ -1842,7 +1854,7 @@ channel_tls_process_netinfo_cell(cell_t *cell, channel_tls_t *chan)
/* Act on apparent skew. */
/** Warn when we get a netinfo skew with at least this value. */
#define NETINFO_NOTICE_SKEW 3600
- if (labs(apparent_skew) > NETINFO_NOTICE_SKEW &&
+ if (time_abs(apparent_skew) > NETINFO_NOTICE_SKEW &&
(started_here ||
connection_or_digest_is_known_relay(chan->conn->identity_digest))) {
int trusted = router_digest_is_trusted_dir(chan->conn->identity_digest);