[PATCH] ipcpd: Fix initialization of hash width in DHT

  • From: Dimitri Staessens <dimitri@ouroboros.rocks>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Tue, 15 Feb 2022 22:03:17 +0100

The width of the Kademlia hash function (dht->b) was set only after
the ID was created. This should have failed miserably, but the bytes
after were fine as they were just a randomized ID in the Kademlia
network. Nasty.

Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
---
 src/ipcpd/unicast/dir/dht.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/ipcpd/unicast/dir/dht.c b/src/ipcpd/unicast/dir/dht.c
index 1742267b..959fc179 100644
--- a/src/ipcpd/unicast/dir/dht.c
+++ b/src/ipcpd/unicast/dir/dht.c
@@ -2249,6 +2249,12 @@ int dht_bootstrap(void * dir)
 
         pthread_rwlock_wrlock(&dht->lock);
 
+#ifndef __DHT_TEST__
+        dht->b        = hash_len(ipcpi.dir_hash_algo);
+#else
+        dht->b        = DHT_TEST_KEY_LEN;
+#endif
+
         dht->id = create_id(dht->b);
         if (dht->id == NULL)
                 goto fail_id;
@@ -2259,11 +2265,7 @@ int dht_bootstrap(void * dir)
 
         dht->buckets->depth = 0;
         dht->buckets->mask  = 0;
-#ifndef __DHT_TEST__
-        dht->b        = hash_len(ipcpi.dir_hash_algo);
-#else
-        dht->b        = DHT_TEST_KEY_LEN;
-#endif
+
         dht->t_expire = 86400; /* 1 day */
         dht->t_repub  = dht->t_expire - 10;
         dht->k        = KAD_K;
-- 
2.35.1


Other related posts:

  • » [PATCH] ipcpd: Fix initialization of hash width in DHT - Dimitri Staessens