Browse Source

Fixed a race condition if a connection is closed during handshaking.

Steven Engler 4 years ago
parent
commit
7acfec5665
1 changed files with 15 additions and 5 deletions
  1. 15 5
      src/core/or/safe_connection.c

+ 15 - 5
src/core/or/safe_connection.c

@@ -711,9 +711,14 @@ safe_or_connection_tls_secrets(safe_or_connection_t *safe_or_conn,
   tor_assert(safe_or_conn != NULL);
   tor_assert(secrets_out != NULL);
   tor_mutex_acquire(&TO_SAFE_CONN(safe_or_conn)->lock);
-  tor_assert(safe_or_conn->tls != NULL);
 
-  int rv = tor_tls_get_tlssecrets(safe_or_conn->tls, secrets_out);
+  int rv = -1;
+
+  if (safe_or_conn->tls == NULL){
+    log_warn(LD_OR, "safe_or_conn->tls is NULL");
+  } else {
+    rv = tor_tls_get_tlssecrets(safe_or_conn->tls, secrets_out);
+  }
 
   tor_mutex_release(&TO_SAFE_CONN(safe_or_conn)->lock);
   return rv;
@@ -727,10 +732,15 @@ safe_or_connection_key_material(safe_or_connection_t *safe_or_conn,
 {
   tor_assert(safe_or_conn != NULL);
   tor_mutex_acquire(&TO_SAFE_CONN(safe_or_conn)->lock);
-  tor_assert(safe_or_conn->tls != NULL);
 
-  int rv = tor_tls_export_key_material(safe_or_conn->tls, secrets_out,
-                                       context, context_len, label);
+  int rv = -1;
+
+  if (safe_or_conn->tls == NULL){
+    log_warn(LD_OR, "safe_or_conn->tls is NULL");
+  } else {
+    rv = tor_tls_export_key_material(safe_or_conn->tls, secrets_out,
+                                     context, context_len, label);
+  }
 
   tor_mutex_release(&TO_SAFE_CONN(safe_or_conn)->lock);
   return rv;