[tor-commits] [tor/release-0.4.1] Merge branch 'ticket31343_035' into ticket31343_040

nickm at torproject.org nickm at torproject.org
Thu Aug 8 15:24:33 UTC 2019


commit 79569d86b36ae1a89b5656bf8356247574b32e95
Merge: 2a42d6be2 bc9492a93
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Aug 6 11:18:40 2019 -0400

    Merge branch 'ticket31343_035' into ticket31343_040

 changes/bug31343         |  9 +++++++++
 src/core/or/channeltls.c | 20 ++++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --cc src/core/or/channeltls.c
index f552b2077,91a424728..5a00a9e00
--- a/src/core/or/channeltls.c
+++ b/src/core/or/channeltls.c
@@@ -1635,36 -1637,19 +1635,48 @@@ channel_tls_process_padding_negotiate_c
  }
  
  /**
 + * Convert <b>netinfo_addr</b> into corresponding <b>tor_addr</b>.
 + * Return 0 on success; on failure, return -1 and log a warning.
 + */
 +static int
 +tor_addr_from_netinfo_addr(tor_addr_t *tor_addr,
 +                           const netinfo_addr_t *netinfo_addr) {
 +  tor_assert(tor_addr);
 +  tor_assert(netinfo_addr);
 +
 +  uint8_t type = netinfo_addr_get_addr_type(netinfo_addr);
 +  uint8_t len = netinfo_addr_get_len(netinfo_addr);
 +
 +  if (type == NETINFO_ADDR_TYPE_IPV4 && len == 4)  {
 +    uint32_t ipv4 = netinfo_addr_get_addr_ipv4(netinfo_addr);
 +    tor_addr_from_ipv4h(tor_addr, ipv4);
 +  } else if (type == NETINFO_ADDR_TYPE_IPV6 && len == 16) {
 +    const uint8_t *ipv6_bytes = netinfo_addr_getconstarray_addr_ipv6(
 +                                  netinfo_addr);
 +    tor_addr_from_ipv6_bytes(tor_addr, (const char *)ipv6_bytes);
 +  } else {
 +    log_fn(LOG_PROTOCOL_WARN, LD_OR, "Cannot read address from NETINFO "
 +                                     "- wrong type/length.");
 +    return -1;
 +  }
 +
 +  return 0;
 +}
 +
 +/**
-  * 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".
@@@ -1745,29 -1732,21 +1757,29 @@@ channel_tls_process_netinfo_cell(cell_
    }
  
    /* Decode the cell. */
 -  timestamp = ntohl(get_uint32(cell->payload));
 -  const time_t sent_versions_at =
 -    chan->conn->handshake_state->sent_versions_at;
 -  if (now > sent_versions_at && (now - sent_versions_at) < 180) {
 -    /* If we have gotten the NETINFO cell reasonably soon after having
 -     * sent our VERSIONS cell, maybe we can learn skew information from it. */
 -    apparent_skew = now - timestamp;
 +  netinfo_cell_t *netinfo_cell = NULL;
 +
 +  ssize_t parsed = netinfo_cell_parse(&netinfo_cell, cell->payload,
 +                                      CELL_PAYLOAD_SIZE);
 +
 +  if (parsed < 0) {
 +    log_fn(LOG_PROTOCOL_WARN, LD_OR,
 +           "Failed to parse NETINFO cell - closing connection.");
 +    connection_or_close_for_error(chan->conn, 0);
 +    return;
    }
  
 -  my_addr_type = (uint8_t) cell->payload[4];
 -  my_addr_len = (uint8_t) cell->payload[5];
 -  my_addr_ptr = (uint8_t*) cell->payload + 6;
 -  end = cell->payload + CELL_PAYLOAD_SIZE;
 -  cp = cell->payload + 6 + my_addr_len;
 +  timestamp = netinfo_cell_get_timestamp(netinfo_cell);
  
 +  const netinfo_addr_t *my_addr =
 +    netinfo_cell_getconst_other_addr(netinfo_cell);
 +
 +  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:
     *    if (my_addr_len >= CELL_PAYLOAD_SIZE - 6) {
     *





More information about the tor-commits mailing list