My last mail was break into a lot of parts. Here is the program 
fragment who's generate an error.


rsa = RSA_generate_key(1024, RSA_F4, NULL, NULL);
if (rsa == NULL)
{
        ERR_print_errors_fp(stderr);
        exit(1);
}
if (RSA_check_key(rsa) <= 0)
{
        ERR_print_errors_fp(stderr);
        exit(1);
}
pvk_len = i2d_RSAPrivateKey(rsa, NULL);
if (pvk_len< 0) exit(1);
pvk_buf  = (unsigned char *)malloc(pvk_len*sizeof(unsigned char));
if (pvk_buf == NULL) exit(1);
pvk_len = i2d_RSAPrivateKey(rsa, &pvk_buf);

/* There are some data in pvk_buf, but are corrupted. */
free(pvk_buf);
/* This causes segmentation fault */

I fixed this by:
pvk_len = i2d_RSAPrivateKey(rsa, NULL);
pvk_buf = (unsigned char *)malloc(pvk_len*2*sizeof(unsigned char));
                                                                                  ^^^^^
/* need allocate two many size of buffer */
org_pointer_buf = pvk_buf;
pvk_len = i2d_RSAPrivateKey(rsa, &pvk_buf);

/* here is the pvk_buf pointer shifted about pvk_len bytes far from 
 original position stored in org_pointer_buf (WHY??) 
*/

free(org_pointer_buf);
/* freed OK */

Thank you.
                            George
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to