[tor-commits] [tor/master] addr: Static assert resolved address cache size

nickm at torproject.org nickm at torproject.org
Thu Jul 9 18:31:12 UTC 2020


commit 7bc54ccba9b9a9ac2ee9f5c1ecccd1d13afbcdda
Author: David Goulet <dgoulet at torproject.org>
Date:   Thu Jul 9 13:33:52 2020 -0400

    addr: Static assert resolved address cache size
    
    This will make sure that we always properly initialize the cache by the exact
    size all the time.
    
    Related to #40022
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/app/config/resolve_addr.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index 9e7c23c88..fb5cb2ed6 100644
--- a/src/app/config/resolve_addr.c
+++ b/src/app/config/resolve_addr.c
@@ -42,15 +42,17 @@ typedef enum {
 } fn_address_ret_t;
 
 /** Last resolved addresses. */
-static tor_addr_t last_resolved_addrs[IDX_SIZE] =
+static tor_addr_t last_resolved_addrs[] =
   { TOR_ADDR_NULL, TOR_ADDR_NULL, TOR_ADDR_NULL };
+CTASSERT(ARRAY_LENGTH(last_resolved_addrs) == IDX_SIZE);
 
 /** Last suggested addresses.
  *
  * These addresses come from a NETINFO cell from a trusted relay (currently
  * only authorities). We only use those in last resort. */
-static tor_addr_t last_suggested_addrs[IDX_SIZE] =
+static tor_addr_t last_suggested_addrs[] =
   { TOR_ADDR_NULL, TOR_ADDR_NULL, TOR_ADDR_NULL };
+CTASSERT(ARRAY_LENGTH(last_suggested_addrs) == IDX_SIZE);
 
 static inline int
 af_to_idx(const int family)
@@ -422,7 +424,9 @@ resolved_addr_set_last(const tor_addr_t *addr, const char *method_used,
                        const char *hostname_used)
 {
   /** Have we done a first resolve. This is used to control logging. */
-  static bool have_resolved_once[IDX_SIZE] = { false, false, false };
+  static bool have_resolved_once[] = { false, false, false };
+  CTASSERT(ARRAY_LENGTH(have_resolved_once) == IDX_SIZE);
+
   bool *done_one_resolve;
   bool have_hostname = false;
   tor_addr_t *last_resolved;





More information about the tor-commits mailing list