Steve wrote:
> > 2. Problem with ASN1_INTEGER_to_BN
> > 
> > In OpenSSL there is following code:
> > 
> > BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
> > {
> >     BIGNUM *ret;
> > 
> >     if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
> >         ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
> >     if(ai->type == V_ASN1_NEG_INTEGER) bn->neg = 1;
> >     return(ret);
> > }
> > 
> > I wonder what will happen if I write my code like this:
> > 
> > BIGNUM *mybig = NULL;
> > 
> > mybig = ASN1_INTEGER_to_BN(some_previously_defined_int, mybig);
> > 
> > In my opinion everything will be fine up to the point where BN_bin2bn
> > fails. Now if (BN_bin2bn returns NULL) AND (some_previously_defined_int
> > happens to be negative) then SIGSEGV is on the fly. Am I right?
> > 
> 
> Yes that is a typo. It should change 'ret' instead of 'bn'.

I don't think that is quite enough.
If BN_bin2bn returns NULL, there would still be a problem.

Rather, I think you need something like:

  if (ret && ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1;

Svenning
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to