summaryrefslogtreecommitdiff
path: root/src/feature/client
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2021-07-06 13:22:59 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2021-07-06 13:22:59 +0300
commit1f87269cf47e2c01ef500405a971b17130c8bb72 (patch)
treedc130fb2121485d0374e6c2ddff449a849e92cff /src/feature/client
parent52c5b8aa12cc613e145600826965917ae10b7cbb (diff)
downloadtor-1f87269cf47e2c01ef500405a971b17130c8bb72.tar.gz
tor-1f87269cf47e2c01ef500405a971b17130c8bb72.zip
Code improvements
Diffstat (limited to 'src/feature/client')
-rw-r--r--src/feature/client/entrynodes.c17
-rw-r--r--src/feature/client/entrynodes.h2
2 files changed, 13 insertions, 6 deletions
diff --git a/src/feature/client/entrynodes.c b/src/feature/client/entrynodes.c
index 58faa8033c..5c6152449a 100644
--- a/src/feature/client/entrynodes.c
+++ b/src/feature/client/entrynodes.c
@@ -3996,8 +3996,14 @@ get_max_lifetime_of_layer2_hs_guards(void)
static int
get_layer2_hs_guard_lifetime(void)
{
- return crypto_rand_int_range(get_min_lifetime_of_layer2_hs_guards(),
- get_max_lifetime_of_layer2_hs_guards());
+ int min = get_min_lifetime_of_layer2_hs_guards();
+ int max = get_max_lifetime_of_layer2_hs_guards();
+
+ if (BUG(min >= max)) {
+ return min;
+ }
+
+ return crypto_rand_int_range(min, max);
}
/** Maintain the L2 guard list. Make sure the list contains enough guards, do
@@ -4107,9 +4113,10 @@ purge_vanguards_lite(void)
/** Return a routerset containing the L2 guards or NULL if it's not yet
* initialized. Callers must not free the routerset. Designed for use in
- * pick_vanguard_middle_node() and should not be used anywhere else (because
- * the routerset pointer can dangle under your feet) */
-routerset_t *
+ * pick_vanguard_middle_node() and should not be used anywhere else. Do not
+ * store this pointer -- any future calls to maintain_layer2_guards() and
+ * purge_vanguards_lite() can invalidate it. */
+const routerset_t *
get_layer2_guards(void)
{
if (!layer2_guards) {
diff --git a/src/feature/client/entrynodes.h b/src/feature/client/entrynodes.h
index c1bc5b41c1..9c38c2b5f8 100644
--- a/src/feature/client/entrynodes.h
+++ b/src/feature/client/entrynodes.h
@@ -651,7 +651,7 @@ guard_get_guardfraction_bandwidth(guardfraction_bandwidth_t *guardfraction_bw,
int orig_bandwidth,
uint32_t guardfraction_percentage);
-routerset_t *get_layer2_guards(void);
+const routerset_t *get_layer2_guards(void);
void maintain_layer2_guards(void);
void purge_vanguards_lite(void);