Angus Lee wrote:
>
> Hi,
>
> Does the following piece of code have any problem? I got i = 0 when I first
> run it yesterday night, but a couple minutes later when I run it again, i =
> -1. I passed the same thing to this function. I think it shouldn't gave
> different results, am I right?
>
See comments below...
> bool is_user_accessible(unsigned char **cert, unsigned int cert_len, unsigned
> char *document_filename, unsigned int filename_len) {
> bool return_value = false;
> BIO *in = BIO_new(BIO_s_mem());
> BUF_MEM *bm = BUF_MEM_new();
> X509 *x = NULL;
> X509_NAME *name;
> ASN1_OBJECT *obj;
> int i, last;
> X509_NAME_ENTRY *ne;
> ASN1_STRING *common_name = NULL, *email = NULL;
>
> BIO_set_mem_buf(in, bm, 0);
> BIO_write(in, *cert, cert_len);
> if ((x = (X509 *)PEM_read_bio_X509(in, NULL, NULL, NULL)) != NULL) {
> name = (X509_NAME *)X509_get_subject_name(x);
The two casts above are unnecessary.
> /* common name */
> obj = OBJ_nid2obj(NID_commonName);
> i = X509_NAME_get_index_by_OBJ(name, obj, last);
Here's the real problem. 'last' is unitialized. 'last' tells it where to
start the search. Either set last to -1 or just pass -1 for this
parameter.
Steve.
--
Dr Stephen N. Henson. http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED]
Senior crypto engineer, Celo Communications: http://www.celocom.com/
Core developer of the OpenSSL project: http://www.openssl.org/
Business Email: [EMAIL PROTECTED] PGP key: via homepage.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]