> > > That's because the ASN1_OBJECT is a little different. Some standard OIDs 
> > > are
> > > set to a fixed value to avoid the need to keep allocating them. What that
> > > means in practice is you do something like:
> > > 
> > > foo->usage = OBJ_something(somearg);
> > > 
> > > This wont result in a memory leak because the OID isn't dynamically 
> > > allocated.
> > 
> > I would also be using custom OIDs. Would I need to first register the OIDs
> > using OBJ_create? Normally we don't use any name identifier. Or is there
> > a way to duplicate an ASN1_OBJECT?
> > 
> > Otherwise I can probably write an auxillary function to handle this in
> > a similar vein to OBJ_dup(ASN1_OBJECT *).
> > 
> 
> You can use OBJ_txt2obj to created an ASN1_OBJECT from the numerical form if
> you wish. OBJ_dup will duplicate an ASN1_OBJECT just fine.

Thanks, but perhaps I am a little unclear about the issue I'm having.

I have written the following code to demonstrate the issue I'm having,
specifically with ASN1_OBJECT in a custom ASN1 struct containing only
one ASN1_OBJECT type.

I just have a basic ASN1 sequence containing an ASN1_OBJECT. I want
to assign the custom OID "1.2.3.4" to obj. When I try to do this with
OBJ_txt2obj(), this becomes the cause for a segfault on i2d_basic().

I'm unsure why this segfault occurs. My guess is obj is already
allocated by simple_asn_new(); therefore reassigning it with
a newly created object from OBJ_txt2obj() causes a segfault.
But I'm not too familiar with the internals of the i2d_* routine
to see how this is possible.

Ideally I would just like to assign any custom ASN1_OBJECT for obj,
which is where I'm struggling.

Thanks.

#include <openssl/asn1.h>
#include <openssl/asn1t.h>

typedef struct simple_asn_st
{ 
     ASN1_OBJECT *obj;
} simple_asn;

ASN1_SEQUENCE(simple_asn) = {
     ASN1_SIMPLE(simple_asn, obj, ASN1_OBJECT)
} ASN1_SEQUENCE_END(simple_asn)

IMPLEMENT_ASN1_FUNCTIONS(simple_asn)

int main(int argc, char **argv)
{    
     simple_asn *b = simple_asn_new();
     b->obj = OBJ_txt2obj("1.2.3.4", 1);
     i2d_simple_asn(b, NULL); // segfaults here
     return (0);
}
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to