Application crashes when trying to access X509 Certificate Extension returned by X509_get_ext method
by Sanjay Bhat
Google me that
REPLY TO AUTHOR
Google me that
REPLY TO GROUP
--------------------------------------------------------------------------------
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.