Browse Source

Hiding crypt_path_t: Ensure that ->private is initialized.

Now that we are using a constructor we should be more careful that we are
always using the constructor to initialize crypt_path_t, so make sure that
->private is initialized.
George Kadianakis 6 years ago
parent
commit
cd38e41620
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/core/or/crypt_path.c

+ 10 - 1
src/core/or/crypt_path.c

@@ -108,6 +108,7 @@ assert_cpath_layer_ok(const crypt_path_t *cp)
 //  tor_assert(cp->port);
 //  tor_assert(cp->port);
   tor_assert(cp);
   tor_assert(cp);
   tor_assert(cp->magic == CRYPT_PATH_MAGIC);
   tor_assert(cp->magic == CRYPT_PATH_MAGIC);
+  tor_assert(cp->private);
   switch (cp->state)
   switch (cp->state)
     {
     {
     case CPATH_STATE_OPEN:
     case CPATH_STATE_OPEN:
@@ -152,6 +153,7 @@ circuit_init_cpath_crypto(crypt_path_t *cpath,
 {
 {
 
 
   tor_assert(cpath);
   tor_assert(cpath);
+  tor_assert(cpath->private);
   return relay_crypto_init(&cpath->private->crypto, key_data, key_data_len, reverse,
   return relay_crypto_init(&cpath->private->crypto, key_data, key_data_len, reverse,
                            is_hs_v3);
                            is_hs_v3);
 }
 }
@@ -161,7 +163,7 @@ circuit_init_cpath_crypto(crypt_path_t *cpath,
 void
 void
 circuit_free_cpath_node(crypt_path_t *victim)
 circuit_free_cpath_node(crypt_path_t *victim)
 {
 {
-  if (!victim)
+  if (!victim || BUG(!victim->private))
     return;
     return;
 
 
   relay_crypto_clear(&victim->private->crypto);
   relay_crypto_clear(&victim->private->crypto);
@@ -181,6 +183,9 @@ circuit_free_cpath_node(crypt_path_t *victim)
 void
 void
 cpath_crypt_cell(const crypt_path_t *cpath, uint8_t *payload, bool is_decrypt)
 cpath_crypt_cell(const crypt_path_t *cpath, uint8_t *payload, bool is_decrypt)
 {
 {
+  tor_assert(cpath);
+  tor_assert(cpath->private);
+
   if (is_decrypt) {
   if (is_decrypt) {
     relay_crypt_one_payload(cpath->private->crypto.b_crypto, payload);
     relay_crypt_one_payload(cpath->private->crypto.b_crypto, payload);
   } else {
   } else {
@@ -192,6 +197,8 @@ cpath_crypt_cell(const crypt_path_t *cpath, uint8_t *payload, bool is_decrypt)
 struct crypto_digest_t *
 struct crypto_digest_t *
 cpath_get_incoming_digest(const crypt_path_t *cpath)
 cpath_get_incoming_digest(const crypt_path_t *cpath)
 {
 {
+  tor_assert(cpath);
+  tor_assert(cpath->private);
   return cpath->private->crypto.b_digest;
   return cpath->private->crypto.b_digest;
 }
 }
 
 
@@ -200,5 +207,7 @@ cpath_get_incoming_digest(const crypt_path_t *cpath)
 void
 void
 cpath_set_cell_forward_digest(crypt_path_t *cpath, cell_t *cell)
 cpath_set_cell_forward_digest(crypt_path_t *cpath, cell_t *cell)
 {
 {
+  tor_assert(cpath);
+  tor_assert(cpath->private);
   relay_set_digest(cpath->private->crypto.f_digest, cell);
   relay_set_digest(cpath->private->crypto.f_digest, cell);
 }
 }