On Mon, Feb 18, 2013 at 3:04 AM, Nick <nos...@codesniffer.com> wrote:
> On Mon, 2013-02-18 at 00:37 +0100, Dr. Stephen Henson wrote:
>> That's because it is attempting to free up parts of a pointer that
>> haven't
>> been allocated with OPENSSL_malloc. See:
>>
>> http://www.openssl.org/docs/crypto/d2i_X509.html#WARNINGS
>>
>
> Changing the code to allocate the struct via OPENSSL_malloc does not seg
> fault in a standalone app, but the same exact code seg faults in a
> slightly larger app (dump still points to d2i_RSAPrivateKey_fp).
>
> Does that mean any non-NULL ptr passed to the function must be allocated
> via OPENSSL_malloc?  This line in the man page for d2i_X509 suggested to
> me that a non-NULL ptr need only point to a real structure (ie. could
> not simply be an uninitialized ptr):
>
>     "If *px is not NULL then it is assumed that *px contains a valid
> X509 structure and an attempt is made to reuse it."
>
>
> Accordingly, I currently have this d2i_X509_fp code which does not
> segfault:
>
>         X509 x509;
>         X509 *pTmpX509(&x509);
>         X509 *pX509 = d2i_X509_fp(pFile2, &pTmpX509);
The signature is X509 *d2i_X509_fp(FILE *fp, X509 **x);

You might be sending junk into OpenSSL for processing. Perhaps the
following would be better (let the optimizer decide what constitutes a
dead write);

    X509 x509 = NULL;
    X509 *pX509 = d2i_X509_fp(pFile, &x509);

Jeff
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to