aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-01-15 13:25:13 -0500
committerNick Mathewson <nickm@torproject.org>2011-01-15 13:25:13 -0500
commit1393985768d760e11e45faabb537d28248306e8b (patch)
tree61b35b3b734f8a920a08cc9a9ecb70e408cd4a58 /src/common
parent9d133464c874191414dd51f546d09364419040cf (diff)
parentb97b0efec81c5564999c2545dd7f0ca230b239cc (diff)
downloadtor-1393985768d760e11e45faabb537d28248306e8b.tar
tor-1393985768d760e11e45faabb537d28248306e8b.tar.gz
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.c14
-rw-r--r--src/common/crypto.h2
2 files changed, 9 insertions, 7 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 15b58188e..1d12a9d32 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 29ba36cdf..c306bec27 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);