[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] prop224: Add a function to clear INTRO data



commit 7c543412fc4c77a58fb928c6eb322e48fae97137
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Tue Aug 22 14:37:33 2017 -0400

    prop224: Add a function to clear INTRO data
    
    New function named hs_cell_introduce1_data_clear() is introduced to clear off
    an hs_cell_introduce1_data_t object.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/or/hs_cell.c    | 15 +++++++++++++++
 src/or/hs_cell.h    |  3 +++
 src/or/hs_circuit.c |  6 +-----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/or/hs_cell.c b/src/or/hs_cell.c
index 482fa04e9..5244cfa3d 100644
--- a/src/or/hs_cell.c
+++ b/src/or/hs_cell.c
@@ -931,3 +931,18 @@ hs_cell_parse_rendezvous2(const uint8_t *payload, size_t payload_len,
   return ret;
 }
 
+/* Clear the given INTRODUCE1 data structure data. */
+void
+hs_cell_introduce1_data_clear(hs_cell_introduce1_data_t *data)
+{
+  if (data == NULL) {
+    return;
+  }
+  /* Object in this list have been moved to the cell object when building it
+   * so they've been freed earlier. We do that in order to avoid duplicating
+   * them leading to more memory and CPU time being used for nothing. */
+  smartlist_free(data->link_specifiers);
+  /* The data object has no ownership of any members. */
+  memwipe(data, 0, sizeof(hs_cell_introduce1_data_t));
+}
+
diff --git a/src/or/hs_cell.h b/src/or/hs_cell.h
index 14dd31c9d..5136fce93 100644
--- a/src/or/hs_cell.h
+++ b/src/or/hs_cell.h
@@ -115,5 +115,8 @@ int hs_cell_parse_rendezvous2(const uint8_t *payload, size_t payload_len,
                               uint8_t *handshake_info,
                               size_t handshake_info_len);
 
+/* Util API. */
+void hs_cell_introduce1_data_clear(hs_cell_introduce1_data_t *data);
+
 #endif /* TOR_HS_CELL_H */
 
diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
index 819d25432..7d41a33c8 100644
--- a/src/or/hs_circuit.c
+++ b/src/or/hs_circuit.c
@@ -1079,11 +1079,7 @@ hs_circ_send_introduce1(origin_circuit_t *intro_circ,
   goto done;
 
  done:
-  /* Object in this list have been moved to the cell object when building it
-   * so they've been freed earlier. We do that in order to avoid duplicating
-   * them leading to more memory and CPU time being used for nothing. */
-  smartlist_free(intro1_data.link_specifiers);
-  memwipe(&intro1_data, 0, sizeof(intro1_data));
+  hs_cell_introduce1_data_clear(&intro1_data);
   memwipe(payload, 0, sizeof(payload));
   return ret;
 }



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits