Initialize cert either to null or to a valid X509_REQ object
(X509_REQ_new()) before d2i.

If null a new object will be allocated and the pointer set; if nonnull the
object will be reused.

 

See the man page for d2i_X509 especially under WARNINGS. Lots of info about
d2i_x and i2d_x 

routines for all types x is in the d2i/i2d_X509_* man page apparently for
historical reasons.

 

Aside- if you care about portability to Windows, fopen DER files with mode
including "b".

 

From: owner-openssl-us...@openssl.org
[mailto:owner-openssl-us...@openssl.org] On Behalf Of Nikita Koptelov
Sent: Tuesday, March 18, 2014 08:21
To: openssl-users@openssl.org
Subject: *** Spam *** CRYPTO_add_lock segfault when attempting to open X509
CSR

 

Good day,

I'm trying to use openSSL libs to parse certificate request, but something
goes wrong.

The thread throws segfault around:

 

 

0x7ffff77fee0a  <+0x007a>         mov    %r8d,%ecx
0x7ffff77fee0d  <+0x007d>         mov    %r13d,(%r12)
0x7ffff77fee11  <+0x0081>         callq  0x7ffff77fe000 <CRYPTO_lock@plt>

 

in CRYPTO_add_lock when using d2i_X509_REQ_fp(). Could anyone help me with
the problem?

 

Code:

    FILE* fp;
    FILE* fperr;
 
    fp = fopen(path,"r");
    if (fp != NULL)
    {
        fperr = fopen("/home/utrk/err","w");
        X509_REQ *cert;
        d2i_X509_REQ_fp(fp,&cert);
        if (!d2i_X509_REQ_fp(fp,&cert))
        {
            ERR_print_errors_fp(fperr);
        }
        fclose(fp);
        fclose(fperr);
    }



 
Full backtrace: http://pastebin.com/q5JkX3fh
 
Best wishes,
 
Nick

Reply via email to