Are you checking to make sure that there *is* data in that extension?
Or that the extension value even exists?

if (NULL == Extension->value) assert("Extension->value NULL");
if (NULL == Extension->value->data) assert ("Extension->value->data NULL");
OrgPtr=Extension->value->data;

-Kyle H

On Fri, Nov 20, 2009 at 3:50 AM, Sanjay Bhat <bsan...@novell.com> wrote:
>
> Hi,
>
> Our application running in windows 2008 64-bit platform crashes when we try
> to access the data member of X509_EXTENSION returned by X509_get_ext().
>
> We are using  0.9.8d version of openssl compiled for windows 64 bit
> platform.
>
> We are clueless why this is happening and are badly stuck with this. Please
> help us.
>
> Here is the code snippet of our application with the point of crash in bold
> :
>
> BOOL GetX509ObjectString(X509 *Certificate, unsigned char *ASN1, unsigned
> char *Short, unsigned char *Description, unsigned char *Buffer, unsigned
> long BufSize)
> {
>     X509_EXTENSION      *Extension;
>     int                 nid;
>     int                 Position;
>     ASN1_STRING         *Value;
>     unsigned char       *OrgPtr;
>
>     if (!Buffer) {
>         return(FALSE);
>     }
>     Buffer[0]='\0';
>
>     nid = OBJ_create(ASN1, Short, Description);
>     Position=X509_get_ext_by_NID(Certificate, nid, -1);
>     if (Position==-1) {
>         return(FALSE);
>     }
>
>  Extension=X509_get_ext(Certificate, Position);
>   if (!Extension) {
>         return(FALSE);
>     }
>
>     /* The M_d2i function alters the pointer, so keep a copy */
>     OrgPtr=Extension->value->data; //This is the point of crash. Referencing
> data member seems to be causing the crash
>     Value=M_d2i_ASN1_IA5STRING(NULL, &(Extension->value->data),
> Extension->value->length);
>     Extension->value->data=OrgPtr;
>     strncpy(Buffer, Value->data, min(Value->length+1, BufSize));
>     Buffer[min(Value->length+1, BufSize)-1]='\0';
>     ASN1_STRING_free(Value);
>     return(TRUE);
> }
>
> Appreciate any kind of help on this is greatly appreciated.
>
> Thanks & Regards,
> Sanjay.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to