why asn1_create_element exits with code 137 but asn1_print_structure don't

47 Views Asked by At

I'm trying to use asn1_create_element() from libtasn1.h but it exist with an error 137. However asn1_print_structure() that uses the same definitions and source works.

asn1_print_structure(stdout, definitions, "IEC61850.GOOSEpdu", ASN1_PRINT_ALL); //Works fine
asn1_node * goose_pdu = NULL;
result = asn1_create_element(definitions, "IEC61850.GOOSEpdu", goose_pdu); //Exits code 137

It seems that it is getting without memory, but i don't know the reason.

The ASN.1 code

IEC61850 {}
DEFINITIONS IMPLICIT TAGS ::= BEGIN

GOOSEpdu ::= CHOICE {
    goosePdu    [APPLICATION 1] IMPLICIT IECGoosePdu
}

IECGoosePdu ::= SEQUENCE {
    gocbRef             [0] IMPLICIT VisibleString,
    timeAllowedtoLive   [1] IMPLICIT INTEGER,
    datSet              [2] IMPLICIT VisibleString,
    goID                [3] IMPLICIT VisibleString OPTIONAL,
    t                   [4] IMPLICIT UtcTime,
    stNum               [5] IMPLICIT INTEGER,
    sqNum               [6] IMPLICIT INTEGER,
    test                [7] IMPLICIT BOOLEAN DEFAULT FALSE,
    confRev             [8] IMPLICIT INTEGER,
    ndsCom              [9] IMPLICIT BOOLEAN DEFAULT FALSE,
    numDatSetEntries    [10] IMPLICIT INTEGER,
    allData             [11] IMPLICIT SEQUENCE OF Data --,
--  security            [12] ANY OPTIONAL
                             -- reserved for digital signature
}

UtcTime ::= OCTET STRING -- format and size defined in 8.1.3.6.

TimeOfDay ::= OCTET STRING -- (SIZE (4 | 6))
FloatingPoint ::= OCTET STRING


Data ::= CHOICE
    {
    -- context tag 0 is reserved for AccessResult
    array               [1] IMPLICIT SEQUENCE OF Data,
    structure           [2] IMPLICIT SEQUENCE OF Data,
    boolean             [3] IMPLICIT BOOLEAN,   
    bit-string          [4] IMPLICIT BIT STRING,
    integer             [5] IMPLICIT INTEGER,
    unsigned            [6] IMPLICIT INTEGER,
    floating-point      [7] IMPLICIT FloatingPoint,
    -- real             [8] IMPLICIT REAL,
    octet-string        [9] IMPLICIT OCTET STRING,
    visible-string      [10] IMPLICIT VisibleString,
    binary-time         [12] IMPLICIT TimeOfDay,
    bcd                 [13] IMPLICIT INTEGER,
    booleanArray        [14] IMPLICIT BIT STRING,
    objId               [15] IMPLICIT OBJECT IDENTIFIER,
    mMSString           [16] IMPLICIT MMSString,
    utc-time            [17] IMPLICIT UtcTime               -- added by IEC61850 8.1 G3 
    }

MMSString ::= UTF8String

END
1

There are 1 best solutions below

0
Carlos Moraes On

Solved simply by using initialized variables:

asn1_node goose_pdu;