]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge branch 'ticket31343_029' into ticket31343_035
authorNick Mathewson <nickm@torproject.org>
Tue, 6 Aug 2019 15:15:20 +0000 (11:15 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 6 Aug 2019 15:15:20 +0000 (11:15 -0400)
1  2 
src/core/or/channeltls.c

index a83d54ed3776960e73220ba59f86e3a855234ea3,ea69792f1205657bcdb428954583f38adea4b49f..91a424728dc2f912983d5fa9a9806e2a61e5529f
@@@ -1599,45 -1583,20 +1599,57 @@@ channel_tls_process_versions_cell(var_c
    }
  }
  
 +/**
 + * Process a 'padding_negotiate' cell.
 + *
 + * This function is called to handle an incoming PADDING_NEGOTIATE cell;
 + * enable or disable padding accordingly, and read and act on its timeout
 + * value contents.
 + */
 +static void
 +channel_tls_process_padding_negotiate_cell(cell_t *cell, channel_tls_t *chan)
 +{
 +  channelpadding_negotiate_t *negotiation;
 +  tor_assert(cell);
 +  tor_assert(chan);
 +  tor_assert(chan->conn);
 +
 +  if (chan->conn->link_proto < MIN_LINK_PROTO_FOR_CHANNEL_PADDING) {
 +    log_fn(LOG_PROTOCOL_WARN, LD_OR,
 +           "Received a PADDING_NEGOTIATE cell on v%d connection; dropping.",
 +           chan->conn->link_proto);
 +    return;
 +  }
 +
 +  if (channelpadding_negotiate_parse(&negotiation, cell->payload,
 +                                     CELL_PAYLOAD_SIZE) < 0) {
 +    log_fn(LOG_PROTOCOL_WARN, LD_OR,
 +          "Received malformed PADDING_NEGOTIATE cell on v%d connection; "
 +          "dropping.", chan->conn->link_proto);
 +
 +    return;
 +  }
 +
 +  channelpadding_update_padding_for_channel(TLS_CHAN_TO_BASE(chan),
 +                                            negotiation);
 +
 +  channelpadding_negotiate_free(negotiation);
 +}
 +
  /**
-  * 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".
@@@ -1652,12 -1612,9 +1664,12 @@@ channel_tls_process_netinfo_cell(cell_
    const uint8_t *cp, *end;
    uint8_t n_other_addrs;
    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;
  
    tor_assert(cell);
    tor_assert(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) &&
 -      router_get_by_id_digest(chan->conn->identity_digest)) {
++  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);
      clock_skew_warning(TO_CONN(chan->conn), apparent_skew, trusted, LD_GENERAL,
                         "NETINFO cell", "OR");