Backport: Fix bug 889: share deep-copied keys between threads to avoid races in reference counts. Bugfix on 0.1.0.1-rc.
svn:r17674
This commit is contained in:
parent
5efd2b2fa7
commit
9b72e96f95
|
@ -46,6 +46,9 @@ Changes in version 0.2.0.33 - 200?-??-??
|
||||||
- Fix a memory leak when we decline to add a v2 rendezvous descriptor to
|
- Fix a memory leak when we decline to add a v2 rendezvous descriptor to
|
||||||
the cache because we already had a v0 descriptor with the same ID.
|
the cache because we already had a v0 descriptor with the same ID.
|
||||||
Bugfix on 0.2.0.18-alpha.
|
Bugfix on 0.2.0.18-alpha.
|
||||||
|
- Fix a race condition when freeing keys shared between main thread
|
||||||
|
and CPU workers that could result in a memory leak. Bugfix on
|
||||||
|
0.1.0.1-rc. Fixes bug 889.
|
||||||
|
|
||||||
o Minor features:
|
o Minor features:
|
||||||
- Report the case where all signatures in a detached set are rejected
|
- Report the case where all signatures in a detached set are rejected
|
||||||
|
|
|
@ -631,6 +631,23 @@ crypto_pk_dup_key(crypto_pk_env_t *env)
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Make a real honest-to-goodness copy of <b>env</b>, and return it. */
|
||||||
|
crypto_pk_env_t *
|
||||||
|
crypto_pk_copy_full(crypto_pk_env_t *env)
|
||||||
|
{
|
||||||
|
RSA *new_key;
|
||||||
|
tor_assert(env);
|
||||||
|
tor_assert(env->key);
|
||||||
|
|
||||||
|
if (PRIVATE_KEY_OK(env)) {
|
||||||
|
new_key = RSAPrivateKey_dup(env->key);
|
||||||
|
} else {
|
||||||
|
new_key = RSAPublicKey_dup(env->key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _crypto_new_pk_env_rsa(new_key);
|
||||||
|
}
|
||||||
|
|
||||||
/** Encrypt <b>fromlen</b> bytes from <b>from</b> with the public key
|
/** Encrypt <b>fromlen</b> bytes from <b>from</b> with the public key
|
||||||
* in <b>env</b>, using the padding method <b>padding</b>. On success,
|
* in <b>env</b>, using the padding method <b>padding</b>. On success,
|
||||||
* write the result to <b>to</b>, and return the number of bytes
|
* write the result to <b>to</b>, and return the number of bytes
|
||||||
|
|
|
@ -88,6 +88,7 @@ int crypto_pk_check_key(crypto_pk_env_t *env);
|
||||||
int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b);
|
int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b);
|
||||||
size_t crypto_pk_keysize(crypto_pk_env_t *env);
|
size_t crypto_pk_keysize(crypto_pk_env_t *env);
|
||||||
crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *orig);
|
crypto_pk_env_t *crypto_pk_dup_key(crypto_pk_env_t *orig);
|
||||||
|
crypto_pk_env_t *crypto_pk_copy_full(crypto_pk_env_t *orig);
|
||||||
|
|
||||||
int crypto_pk_public_encrypt(crypto_pk_env_t *env, char *to,
|
int crypto_pk_public_encrypt(crypto_pk_env_t *env, char *to,
|
||||||
const char *from, size_t fromlen, int padding);
|
const char *from, size_t fromlen, int padding);
|
||||||
|
|
|
@ -75,8 +75,8 @@ get_onion_key(void)
|
||||||
return onionkey;
|
return onionkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Store a copy of the current onion key into *<b>key</b>, and a copy
|
/** Store a full copy of the current onion key into *<b>key</b>, and a full
|
||||||
* of the most recent onion key into *<b>last</b>.
|
* copy of the most recent onion key into *<b>last</b>.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last)
|
dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last)
|
||||||
|
@ -85,9 +85,9 @@ dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last)
|
||||||
tor_assert(last);
|
tor_assert(last);
|
||||||
tor_mutex_acquire(key_lock);
|
tor_mutex_acquire(key_lock);
|
||||||
tor_assert(onionkey);
|
tor_assert(onionkey);
|
||||||
*key = crypto_pk_dup_key(onionkey);
|
*key = crypto_pk_copy_full(onionkey);
|
||||||
if (lastonionkey)
|
if (lastonionkey)
|
||||||
*last = crypto_pk_dup_key(lastonionkey);
|
*last = crypto_pk_copy_full(lastonionkey);
|
||||||
else
|
else
|
||||||
*last = NULL;
|
*last = NULL;
|
||||||
tor_mutex_release(key_lock);
|
tor_mutex_release(key_lock);
|
||||||
|
|
Loading…
Reference in New Issue