diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-01-15 13:25:13 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-01-15 13:25:13 -0500 |
commit | 1393985768d760e11e45faabb537d28248306e8b (patch) | |
tree | 61b35b3b734f8a920a08cc9a9ecb70e408cd4a58 /src/common | |
parent | 9d133464c874191414dd51f546d09364419040cf (diff) | |
parent | b97b0efec81c5564999c2545dd7f0ca230b239cc (diff) | |
download | tor-1393985768d760e11e45faabb537d28248306e8b.tar.gz tor-1393985768d760e11e45faabb537d28248306e8b.zip |
Merge remote branch 'origin/maint-0.2.1' into maint-0.2.2
Conflicts:
src/or/routerparse.c
src/or/test.c
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 14 | ||||
-rw-r--r-- | src/common/crypto.h | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 15b58188ed..1d12a9d32d 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -518,21 +518,23 @@ crypto_pk_generate_key_with_bits(crypto_pk_env_t *env, int bits) return 0; } -/** Read a PEM-encoded private key from the string <b>s</b> into <b>env</b>. - * Return 0 on success, -1 on failure. +/** Read a PEM-encoded private key from the <b>len</b>-byte string <b>s</b> + * into <b>env</b>. Return 0 on success, -1 on failure. If len is -1, + * the string is nul-terminated. */ /* Used here, and used for testing. */ int crypto_pk_read_private_key_from_string(crypto_pk_env_t *env, - const char *s) + const char *s, ssize_t len) { BIO *b; tor_assert(env); tor_assert(s); + tor_assert(len < INT_MAX && len < SIZE_T_CEILING); - /* Create a read-only memory BIO, backed by the NUL-terminated string 's' */ - b = BIO_new_mem_buf((char*)s, -1); + /* Create a read-only memory BIO, backed by the string 's' */ + b = BIO_new_mem_buf((char*)s, (int)len); if (env->key) RSA_free(env->key); @@ -566,7 +568,7 @@ crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, } /* Try to parse it. */ - r = crypto_pk_read_private_key_from_string(env, contents); + r = crypto_pk_read_private_key_from_string(env, contents, -1); tor_free(contents); if (r) return -1; /* read_private_key_from_string already warned, so we don't.*/ diff --git a/src/common/crypto.h b/src/common/crypto.h index 29ba36cdf6..c306bec276 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -112,7 +112,7 @@ int crypto_pk_write_private_key_to_string(crypto_pk_env_t *env, int crypto_pk_read_public_key_from_string(crypto_pk_env_t *env, const char *src, size_t len); int crypto_pk_read_private_key_from_string(crypto_pk_env_t *env, - const char *s); + const char *s, ssize_t len); int crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env, const char *fname); |