aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-09-26 18:44:20 +0000
committerNick Mathewson <nickm@torproject.org>2003-09-26 18:44:20 +0000
commita3e08a01192831f8f686c9a03b394dff4031b10f (patch)
treed17c5279230032e01f6022b58295d6b63a7413ea
parent31cee9fe18b01eaaea9fc9e0fd5e1e8bf7baa535 (diff)
downloadtor-a3e08a01192831f8f686c9a03b394dff4031b10f.tar
tor-a3e08a01192831f8f686c9a03b394dff4031b10f.tar.gz
Bugfixes in crypto_pk_write_private_key_to_filename
svn:r489
-rw-r--r--src/common/crypto.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index f6c7360d5..cf209451a 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -479,18 +479,23 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
BIO *bio;
char *cp;
long len;
+ char *s;
int r;
assert(env->type == CRYPTO_PK_RSA);
if (!(bio = BIO_new(BIO_s_mem())))
return -1;
- if (PEM_write_bio_RSAPrivateKey(bio, (RSA*)env->key, NULL,NULL,0,0,NULL)) {
+ if (PEM_write_bio_RSAPrivateKey(bio, (RSA*)env->key, NULL,NULL,0,NULL,NULL)
+ == 0) {
BIO_free(bio);
return -1;
}
len = BIO_get_mem_data(bio, &cp);
- assert(len == strlen(cp));
- r = write_str_to_file(fname, cp);
+ s = tor_malloc(len+1);
+ strncpy(s, cp, len);
+ s[len] = '\0';
+ r = write_str_to_file(fname, s);
BIO_free(bio);
+ free(s);
return r;
}