]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Revert "Hiding crypt_path_t: Create a constructor for crypt_path_t."
authorGeorge Kadianakis <desnacked@riseup.net>
Fri, 26 Apr 2019 11:26:22 +0000 (14:26 +0300)
committerGeorge Kadianakis <desnacked@riseup.net>
Fri, 3 May 2019 15:15:26 +0000 (18:15 +0300)
This reverts commit ab8b80944967ee5a6a0c45dbf61839cf257bfe44.

src/core/or/crypt_path.c
src/core/or/crypt_path.h
src/core/or/crypt_path_st.h
src/feature/hs/hs_circuit.c
src/feature/rend/rendclient.c
src/feature/rend/rendservice.c
src/test/test_circuitpadding.c
src/test/test_hs_client.c
src/test/test_hs_service.c
src/test/test_relaycell.c
src/test/test_relaycrypt.c

index c7ff8690defa75dda8bae7bd017ba6d2d7092924..c44d65231d21bebbd877bed4ea07b7fd4b4efc44 100644 (file)
 #include "core/or/crypt_path_st.h"
 #include "core/or/cell_st.h"
 
-/** Initialize and return a minimal crypt_path_t */
-crypt_path_t *
-crypt_path_new(void)
-{
-  crypt_path_t *cpath = tor_malloc_zero(sizeof(crypt_path_t));
-  cpath->magic = CRYPT_PATH_MAGIC;
-  cpath->private = tor_malloc_zero(sizeof(struct crypt_path_private_t));
-
-  return cpath;
-}
-
 /** Add <b>new_hop</b> to the end of the doubly-linked-list <b>head_ptr</b>.
  * This function is used to extend cpath by another hop.
  */
@@ -71,11 +60,12 @@ cpath_extend_linked_list(crypt_path_t **head_ptr, crypt_path_t *new_hop)
 int
 cpath_append_hop(crypt_path_t **head_ptr, extend_info_t *choice)
 {
-  crypt_path_t *hop = crypt_path_new();
+  crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t));
 
   /* link hop into the cpath, at the end. */
   cpath_extend_linked_list(head_ptr, hop);
 
+  hop->magic = CRYPT_PATH_MAGIC;
   hop->state = CPATH_STATE_CLOSED;
 
   hop->extend_info = extend_info_dup(choice);
@@ -180,7 +170,6 @@ cpath_free(crypt_path_t *victim)
   onion_handshake_state_release(&victim->handshake_state);
   crypto_dh_free(victim->rend_dh_handshake_state);
   extend_info_free(victim->extend_info);
-  tor_free(victim->private);
 
   memwipe(victim, 0xBB, sizeof(crypt_path_t)); /* poison memory */
   tor_free(victim);
index ed59037760b548f759cf472eb2fa665d55d8ef78..19c8571d061965f5872c3aae050686ecb4642f31 100644 (file)
@@ -6,8 +6,6 @@
 #ifndef CRYPT_PATH_H
 #define CRYPT_PATH_H
 
-crypt_path_t *crypt_path_new(void);
-
 void cpath_assert_layer_ok(const crypt_path_t *cp);
 
 void cpath_assert_ok(const crypt_path_t *cp);
index 7da3c57f4971742d956dc86c2a6306413c8bef72..833cfefad1af9300309739243633d79a1e2fd672 100644 (file)
@@ -8,6 +8,9 @@
 #define CRYPT_PATH_ST_H
 
 #include "core/or/relay_crypto_st.h"
+struct crypto_dh_t;
+
+#define CRYPT_PATH_MAGIC 0x70127012u
 
 struct fast_handshake_state_t;
 struct ntor_handshake_state_t;
@@ -23,8 +26,6 @@ struct onion_handshake_state_t {
 
 #ifdef CRYPT_PATH_PRIVATE
 
-#define CRYPT_PATH_MAGIC 0x70127012u
-
 /* The private parts of crypt path that don't need to be exposed to all the
  * modules. */
 struct crypt_path_private_t {
index 7d17aff72f3f4f60125a2eb47e4175f03c6b0481..a6e86c5ab3b184c08a5a98b667d919dbdad45246 100644 (file)
@@ -87,7 +87,8 @@ create_rend_cpath(const uint8_t *ntor_key_seed, size_t seed_len,
   }
 
   /* Setup the cpath */
-  cpath = crypt_path_new();
+  cpath = tor_malloc_zero(sizeof(crypt_path_t));
+  cpath->magic = CRYPT_PATH_MAGIC;
 
   if (cpath_init_circuit_crypto(cpath, (char*)keys, sizeof(keys),
                                 is_service_side, 1) < 0) {
index c6e9dde87836df33e0bfac54fba635978e9cb77e..f84d221b1a8cc913093b256e7443645e9341f3e3 100644 (file)
@@ -16,7 +16,6 @@
 #include "core/or/circuituse.h"
 #include "core/or/connection_edge.h"
 #include "core/or/relay.h"
-#include "core/or/crypt_path.h"
 #include "feature/client/circpathbias.h"
 #include "feature/control/control_events.h"
 #include "feature/dirclient/dirclient.h"
@@ -195,7 +194,9 @@ rend_client_send_introduction(origin_circuit_t *introcirc,
   /* Initialize the pending_final_cpath and start the DH handshake. */
   cpath = rendcirc->build_state->pending_final_cpath;
   if (!cpath) {
-    cpath = rendcirc->build_state->pending_final_cpath = crypt_path_new();
+    cpath = rendcirc->build_state->pending_final_cpath =
+      tor_malloc_zero(sizeof(crypt_path_t));
+    cpath->magic = CRYPT_PATH_MAGIC;
     if (!(cpath->rend_dh_handshake_state = crypto_dh_new(DH_TYPE_REND))) {
       log_warn(LD_BUG, "Internal error: couldn't allocate DH.");
       status = -2;
index 0ecd0e6ff618232370b5c96f5f86b109a57e73e4..98c7253bcc284adbe031ba4829a0079efc35d001 100644 (file)
@@ -2158,7 +2158,8 @@ rend_service_receive_introduction(origin_circuit_t *circuit,
   launched->build_state->service_pending_final_cpath_ref->refcount = 1;
 
   launched->build_state->service_pending_final_cpath_ref->cpath = cpath =
-    crypt_path_new();
+    tor_malloc_zero(sizeof(crypt_path_t));
+  cpath->magic = CRYPT_PATH_MAGIC;
   launched->build_state->expiry_time = now + MAX_REND_TIMEOUT;
 
   cpath->rend_dh_handshake_state = dh;
index e33e56af3fc08c087bead8ab349351c6737b3913..5550488d0f0c7845d6091c23b37f7684394cc3cf 100644 (file)
@@ -115,7 +115,7 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan)
 {
   or_circuit_t *orcirc = NULL;
   circuit_t *circ = NULL;
-  crypt_path_t *tmp_cpath;
+  crypt_path_t tmp_cpath;
   char whatevs_key[CPATH_KEY_MATERIAL_LEN];
 
   orcirc = tor_malloc_zero(sizeof(*orcirc));
@@ -144,15 +144,13 @@ new_fake_orcirc(channel_t *nchan, channel_t *pchan)
   circuit_set_p_circid_chan(orcirc, orcirc->p_circ_id, pchan);
   circuit_set_n_circid_chan(circ, circ->n_circ_id, nchan);
 
-  tmp_cpath = crypt_path_new();
-  if (cpath_init_circuit_crypto(tmp_cpath, whatevs_key,
+  memset(&tmp_cpath, 0, sizeof(tmp_cpath));
+  if (cpath_init_circuit_crypto(&tmp_cpath, whatevs_key,
                                 sizeof(whatevs_key), 0, 0)<0) {
     log_warn(LD_BUG,"Circuit initialization failed");
     return NULL;
   }
-  orcirc->crypto = tmp_cpath->private->crypto;
-  tor_free(tmp_cpath->private);
-  tor_free(tmp_cpath);
+  orcirc->crypto = tmp_cpath.private->crypto;
 
   return orcirc;
 }
@@ -1620,9 +1618,10 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
   circpad_cell_event_nonpadding_received((circuit_t*)client);
 
   // Add a hop to cpath
-  crypt_path_t *hop = crypt_path_new();
+  crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t));
   cpath_extend_linked_list(&TO_ORIGIN_CIRCUIT(client)->cpath, hop);
 
+  hop->magic = CRYPT_PATH_MAGIC;
   hop->state = CPATH_STATE_OPEN;
 
   // add an extend info to indicate if this node supports padding or not.
index cd049b7c47d96a625b93a690f1dde1c4e7f09f0c..7f5f2550760fb56a1322904c624896e2c1af75e5 100644 (file)
 #include "feature/hs/hs_cache.h"
 #include "core/or/circuitlist.h"
 #include "core/or/circuitbuild.h"
-#include "core/or/crypt_path.h"
 #include "core/mainloop/connection.h"
 #include "core/or/connection_edge.h"
 #include "feature/nodelist/networkstatus.h"
 
 #include "core/or/cpath_build_state_st.h"
 #include "core/or/crypt_path_st.h"
+#include "core/or/crypt_path.h"
 #include "feature/dircommon/dir_connection_st.h"
 #include "core/or/entry_connection_st.h"
 #include "core/or/extend_info_st.h"
@@ -146,7 +146,9 @@ helper_get_circ_and_stream_for_test(origin_circuit_t **circ_out,
 
   if (is_legacy) {
     /* Legacy: Setup rend data and final cpath */
-    or_circ->build_state->pending_final_cpath = crypt_path_new();
+    or_circ->build_state->pending_final_cpath =
+      tor_malloc_zero(sizeof(crypt_path_t));
+    or_circ->build_state->pending_final_cpath->magic = CRYPT_PATH_MAGIC;
     or_circ->build_state->pending_final_cpath->rend_dh_handshake_state =
       crypto_dh_new(DH_TYPE_REND);
     tt_assert(
index 08dac04d218d38bdf46b3087bf6cb0f0a81b0b49..8a22e4d5900603f0cf5ce3b14894de61afe6ae89 100644 (file)
@@ -38,7 +38,6 @@
 #include "core/or/circuitbuild.h"
 #include "core/or/circuitlist.h"
 #include "core/or/circuituse.h"
-#include "core/or/crypt_path.h"
 #include "core/or/connection_edge.h"
 #include "core/or/edge_connection_st.h"
 #include "core/or/relay.h"
@@ -62,6 +61,7 @@
 
 #include "core/or/cpath_build_state_st.h"
 #include "core/or/crypt_path_st.h"
+#include "core/or/crypt_path.h"
 #include "feature/nodelist/networkstatus_st.h"
 #include "feature/nodelist/node_st.h"
 #include "core/or/origin_circuit_st.h"
@@ -221,7 +221,8 @@ helper_create_origin_circuit(int purpose, int flags)
 
   circ = origin_circuit_init(purpose, flags);
   tor_assert(circ);
-  circ->cpath = crypt_path_new();
+  circ->cpath = tor_malloc_zero(sizeof(crypt_path_t));
+  circ->cpath->magic = CRYPT_PATH_MAGIC;
   circ->cpath->state = CPATH_STATE_OPEN;
   circ->cpath->package_window = circuit_initial_package_window();
   circ->cpath->deliver_window = CIRCWINDOW_START;
index b48c7ca8acf8bdf9fdcadf7ae5026f387af1893f..0623583511f8271437b7b2cb1ef53c61243e388f 100644 (file)
@@ -16,7 +16,6 @@
 #include "lib/crypt_ops/crypto_rand.h"
 #include "core/or/circuitbuild.h"
 #include "core/or/circuitlist.h"
-#include "core/or/crypt_path.h"
 #include "core/or/connection_edge.h"
 #include "core/or/relay.h"
 #include "test/test.h"
@@ -91,7 +90,8 @@ helper_create_origin_circuit(int purpose, int flags)
 
   circ = origin_circuit_init(purpose, flags);
   tor_assert(circ);
-  circ->cpath = crypt_path_new();
+  circ->cpath = tor_malloc_zero(sizeof(crypt_path_t));
+  circ->cpath->magic = CRYPT_PATH_MAGIC;
   circ->cpath->state = CPATH_STATE_OPEN;
   circ->cpath->package_window = circuit_initial_package_window();
   circ->cpath->deliver_window = CIRCWINDOW_START;
index 1977958d1f4440731ec8cbb60537601e530138e9..5dc6b47d74c562811c5395094b650c2d9d21f211 100644 (file)
@@ -50,7 +50,7 @@ testing_circuitset_setup(const struct testcase_t *testcase)
   cs->origin_circ = origin_circuit_new();
   cs->origin_circ->base_.purpose = CIRCUIT_PURPOSE_C_GENERAL;
   for (i=0; i<3; ++i) {
-    crypt_path_t *hop = crypt_path_new();
+    crypt_path_t *hop = tor_malloc_zero(sizeof(*hop));
     relay_crypto_init(&hop->private->crypto, KEY_MATERIAL[i],
                       sizeof(KEY_MATERIAL[i]), 0, 0);
     hop->state = CPATH_STATE_OPEN;