[or-cvs] [tor/maint-0.2.2] Properly refcount client_identity_key

nickm at torproject.org nickm at torproject.org
Tue Oct 26 17:56:54 UTC 2010


Author: Sebastian Hahn <sebastian at torproject.org>
Date: Tue, 26 Oct 2010 18:22:04 +0200
Subject: Properly refcount client_identity_key
Commit: 213139f887edd5f366108e72d77c33bcfa3f8ba9

In a2bb0bf we started using a separate client identity key. When we are
in "public server mode" (that means not a bridge) we will use the same
key. Reusing the key without doing the proper refcounting leads to a
segfault on cleanup during shutdown. Fix that.

Also introduce an assert that triggers if our refcount falls below 0.
That should never happen.
---
 src/common/crypto.c |    1 +
 src/or/router.c     |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/common/crypto.c b/src/common/crypto.c
index bfb81d3..b49547f 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -405,6 +405,7 @@ crypto_free_pk_env(crypto_pk_env_t *env)
 
   if (--env->refs > 0)
     return;
+  tor_assert(env->refs == 0);
 
   if (env->key)
     RSA_free(env->key);
diff --git a/src/or/router.c b/src/or/router.c
index 3fd7b7f..725a515 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -573,7 +573,7 @@ init_keys(void)
    * otherwise, set the server identity key as our client identity
    * key. */
   if (public_server_mode(options)) {
-    set_client_identity_key(prkey); /* set above */
+    set_client_identity_key(crypto_pk_dup_key(prkey)); /* set above */
   } else {
     if (!(prkey = crypto_new_pk_env()))
       return -1;
-- 
1.7.1



More information about the tor-commits mailing list