Browse Source

Use assertions so GCC LTO doesn't worry about TLS channel conversion

Part of #27772
Nick Mathewson 5 years ago
parent
commit
965549aa07

+ 6 - 5
src/core/mainloop/connection.c

@@ -656,14 +656,15 @@ connection_free_minimal(connection_t *conn)
     tor_free(or_conn->nickname);
     if (or_conn->chan) {
       /* Owww, this shouldn't happen, but... */
+      channel_t *base_chan = TLS_CHAN_TO_BASE(or_conn->chan);
+      tor_assert(base_chan);
       log_info(LD_CHANNEL,
                "Freeing orconn at %p, saw channel %p with ID "
                "%"PRIu64 " left un-NULLed",
-               or_conn, TLS_CHAN_TO_BASE(or_conn->chan),
-               (
-                 TLS_CHAN_TO_BASE(or_conn->chan)->global_identifier));
-      if (!CHANNEL_FINISHED(TLS_CHAN_TO_BASE(or_conn->chan))) {
-        channel_close_for_error(TLS_CHAN_TO_BASE(or_conn->chan));
+               or_conn, base_chan,
+               base_chan->global_identifier);
+      if (!CHANNEL_FINISHED(base_chan)) {
+        channel_close_for_error(base_chan);
       }
 
       or_conn->chan->conn = NULL;

+ 2 - 0
src/core/or/channel.c

@@ -3423,6 +3423,8 @@ channel_rsa_id_group_set_badness(struct channel_list_s *lst, int force)
   /* it would be more efficient to do a slice, but this case is rare */
   smartlist_t *or_conns = smartlist_new();
   SMARTLIST_FOREACH_BEGIN(channels, channel_t *, channel) {
+    tor_assert(channel); // Suppresses some compiler warnings.
+
     if (!common_ed25519_identity)
       common_ed25519_identity = &channel->ed25519_identity;
 

+ 2 - 0
src/core/or/channelpadding.c

@@ -296,6 +296,7 @@ channelpadding_send_disable_command(channel_t *chan)
   channelpadding_negotiate_t disable;
   cell_t cell;
 
+  tor_assert(chan);
   tor_assert(BASE_CHAN_TO_TLS(chan)->conn->link_proto >=
              MIN_LINK_PROTO_FOR_CHANNEL_PADDING);
 
@@ -328,6 +329,7 @@ channelpadding_send_enable_command(channel_t *chan, uint16_t low_timeout,
   channelpadding_negotiate_t enable;
   cell_t cell;
 
+  tor_assert(chan);
   tor_assert(BASE_CHAN_TO_TLS(chan)->conn->link_proto >=
              MIN_LINK_PROTO_FOR_CHANNEL_PADDING);
 

+ 4 - 0
src/core/or/scheduler_kist.c

@@ -116,6 +116,7 @@ static unsigned int kist_lite_mode = 1;
 static inline size_t
 channel_outbuf_length(channel_t *chan)
 {
+  tor_assert(chan);
   /* In theory, this can not happen because we can not scheduler a channel
    * without a connection that has its outbuf initialized. Just in case, bug
    * on this so we can understand a bit more why it happened. */
@@ -194,6 +195,8 @@ update_socket_info_impl, (socket_table_ent_t *ent))
 {
 #ifdef HAVE_KIST_SUPPORT
   int64_t tcp_space, extra_space;
+  tor_assert(ent);
+  tor_assert(ent->chan);
   const tor_socket_t sock =
     TO_CONN(BASE_CHAN_TO_TLS((channel_t *) ent->chan)->conn)->s;
   struct tcp_info tcp;
@@ -451,6 +454,7 @@ MOCK_IMPL(int, channel_should_write_to_kernel,
  * kernel */
 MOCK_IMPL(void, channel_write_to_kernel, (channel_t *chan))
 {
+  tor_assert(chan);
   log_debug(LD_SCHED, "Writing %lu bytes to kernel for chan %" PRIu64,
             (unsigned long)channel_outbuf_length(chan),
             chan->global_identifier);