Bugfixes in crypto_pk_write_private_key_to_filename

svn:r489
This commit is contained in:
Nick Mathewson 2003-09-26 18:44:20 +00:00
parent 31cee9fe18
commit a3e08a0119

View File

@ -479,18 +479,23 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
BIO *bio; BIO *bio;
char *cp; char *cp;
long len; long len;
char *s;
int r; int r;
assert(env->type == CRYPTO_PK_RSA); assert(env->type == CRYPTO_PK_RSA);
if (!(bio = BIO_new(BIO_s_mem()))) if (!(bio = BIO_new(BIO_s_mem())))
return -1; 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); BIO_free(bio);
return -1; return -1;
} }
len = BIO_get_mem_data(bio, &cp); len = BIO_get_mem_data(bio, &cp);
assert(len == strlen(cp)); s = tor_malloc(len+1);
r = write_str_to_file(fname, cp); strncpy(s, cp, len);
s[len] = '\0';
r = write_str_to_file(fname, s);
BIO_free(bio); BIO_free(bio);
free(s);
return r; return r;
} }