On Tue, Feb 06, 2007, [EMAIL PROTECTED] wrote: > Hi, > I have a slight problem manipulating optional ASN.1 fields. I'm > encoding/decoding a simple DigestInfo structure (by the way, this > corresponds to X509_SIG - I just rebuild my own for the fun ;-)). > > First, I populate my DigestInfo structure and encode it. As the > "parameters" field is optional, note I allocate a new ASN1_TYPE object. > Looks like it's the way to do it, to my understanding. So, then, in the > end, when I have encoded the structure and finally free everything, I > take care to call ASN1_TYPE_free. > > Then, I decode my DER encoded buffer. Strangely, I get > "OID: (nid=0) - undefined" for the OID ! > > If, during encoding, I do NOT free the ASN1_TYPE, then I do retrieve my > OID at decoding time ! > "OID: (nid=64) - sha1" > > I don't understand it, as the DER sequence is the same ! Does somebody > have a hint ? >
You shouldn't free any internal fields in an ASN1 structure even if they are OPTIONAL. The main free function will automatically free them. In you case just calling DigestInfo_free() is sufficient. If you do free internals you'll get a double free which will typically result in undefined behaviour. Steve. -- Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage OpenSSL project core developer and freelance consultant. Funding needed! Details on homepage. Homepage: http://www.drh-consultancy.demon.co.uk ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]