[or-cvs] Bugfixes in crypto_pk_write_private_key_to_filename

Nick Mathewson nickm at seul.org
Fri Sep 26 18:44:22 UTC 2003


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv18700/common

Modified Files:
	crypto.c 
Log Message:
Bugfixes in crypto_pk_write_private_key_to_filename

Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- crypto.c	26 Sep 2003 18:27:34 -0000	1.36
+++ crypto.c	26 Sep 2003 18:44:20 -0000	1.37
@@ -479,18 +479,23 @@
   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;
 }
 



More information about the tor-commits mailing list