Yep, you're right. Thanks for the information.

Patrik


Dr Stephen Henson wrote:

> Patrik Carlsson wrote:
> >
> > You don't need p.
> >
> > Patrik
> >
>
> You do need p... see below.
>
> > Dr Stephen Henson wrote:
> >
> > > The correct way is this...
> > >
> > > int len;
> > > unsigned char *buf, *p;
> > >
> > > len = i2d_PKCS7(p7, NULL);
> > > buf = malloc(len);
> > > p = buf;
> > > i2d_PKCS7(p7, &p);
> > >
>
> When you call any i2d_XXX routine the pointer you pass to it gets
> automatically incremented to point to the end of the data it has just
> written. This is because thats often what you want to do with the ASN1
> routines.
>
> This is usually handled by saving the location of the buffer in a
> temporary variable, in this case p.
>
> If just pass &buf instead then it will end up pointing past the end of
> the buffer after the call and any call to free(buf) will free an invalid
> pointer. This will give the impression that the data written is garbage
> and may also cause segmentation violations later on
>
> The alternative is to do:
> buf -= len;
> after the call in which case you don't need p.
>
> 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
> Development Mailing List                       [EMAIL PROTECTED]
> Automated List Manager                           [EMAIL PROTECTED]

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

Reply via email to