Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000888Taste[All Projects] ASN.1 Compiler v4public2019-11-07 13:092020-08-31 15:32
Reportershd01 
Assigned Togmamais 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Summary0000888:

Bad ACN Decoder generated if ACN key field does not precede its dependent

Description

Using this ASN...

Test DEFINITIONS ::=
BEGIN

MyEnum ::= ENUMERATED {a,b,c}

T-Thing ::= CHOICE {
alt1 INTEGER,
alt2 MyEnum
}

T-ThingHolder ::= SEQUENCE {
random INTEGER,
thing T-Thing
}

END

... with this ACN ...

Test DEFINITIONS ::=
BEGIN

T-ThingHolder [] {
random [],
thing [],
selector INTEGER [encoding pos-int, size 32]
}

T-Thing [] {
alt1 [present-when selector == 1],
alt2 [present-when selector == 10]
}

END

... I get an ACN Decoder that compiles but which crashes at runtime. The problem is that the code generator expects the key field "selector" to be located before the "thing" in the encoded packet.

flag T_ThingHolder_ACN_Decode(T_ThingHolder* pVal, BitStream* pBitStrm, int* pErrCode)
{
flag ret = TRUE;
asn1SccUint T_ThingHolder_selector;
asn1SccUint intVal;

/*Decode random */
ret = BitStream_DecodeUnConstraintWholeNumber(pBitStrm, (&(pVal->random)));   
*pErrCode = ret ? 0 : ERR_ACN_DECODE_T_THINGHOLDER_RANDOM;                               
if (ret) {
    /*Decode thing */
    *pErrCode = 0;
    if ((T_ThingHolder_selector == 1)) { <<<<<<<<<<<<<<<<<<<< uninitialised!
        pVal->thing.kind = alt1_PRESENT;
        ret = BitStream_DecodeUnConstraintWholeNumber(pBitStrm, (&(pVal->thing.u.alt1)));   
        *pErrCode = ret ? 0 : ERR_ACN_DECODE_T_THINGHOLDER_THING_ALT1;                               
    }
    else if ((T_ThingHolder_selector == 10)) {
        pVal->thing.kind = alt2_PRESENT;
        ret = BitStream_DecodeConstraintPosWholeNumber(pBitStrm, (&(intVal)), 0, 2);
        *pErrCode = ret ? 0 : ERR_ACN_DECODE_T_THINGHOLDER_THING_ALT2;
        if (ret) {
            switch (intVal) {
                case 0:
                    pVal->thing.u.alt2 = a;
                    break;
                case 1:
                    pVal->thing.u.alt2 = b;
                    break;
                case 2:
                    pVal->thing.u.alt2 = c;
                    break;
            default:
                ret = FALSE;                            /*COVERAGE_IGNORE*/
                *pErrCode = ERR_ACN_DECODE_T_THINGHOLDER_THING_ALT2;                 /*COVERAGE_IGNORE*/
            }
        }
    }
    else {
        *pErrCode = ERR_ACN_DECODE_T_THINGHOLDER_THING;         /*COVERAGE_IGNORE*/
        ret = FALSE;                    /*COVERAGE_IGNORE*/
    }
    if (ret) {
        /*Decode T_ThingHolder_selector */
        ret = Acn_Dec_Int_PositiveInteger_ConstSize_big_endian_32(pBitStrm, (&(T_ThingHolder_selector)));
        *pErrCode = ret ? 0 : ERR_ACN_DECODE_T_THINGHOLDER_SELECTOR;
    }
}

return ret && T_ThingHolder_IsConstraintValid(pVal, pErrCode);

}

TagsNo tags attached.
Attached Files? file icon shit.acn [^] (269 bytes) 2019-11-07 13:37

- Relationships

-  Notes
(0003667)
shd01 (reporter)
2019-11-07 13:23
edited on: 2019-11-07 13:34

The above ACN looks wrong because I didn't escape it. Here is the correct one (I hope):


Test DEFINITIONS ::=
BEGIN
T-ThingHolder [] {
random [],
thing [],
selector INTEGER [encoding pos-int, size 32]
}
T-Thing [] {
alt1 [present-when selector == 1],
alt2 [present-when selector == 10]
}
END

(0003668)
shd01 (reporter)
2019-11-07 13:35
edited on: 2019-11-07 13:37

Nope, give up. You'll have to imagine the parameters in the ACN

EDIT: I've uploaded a text file

(0003670)
gmamais (developer)
2019-11-07 17:10

I understand the erroneous behavior of the generated code, but I am not sure I understand the requirement.
(1)
Do you want the ASN.1 compiler to report an error when then the selector (or determinant using the uPER terminology) is after its dependent?

or

(2)
Do you want the ASN.1 compiler to support such grammars?
This is much more difficult since the generated code must first decode the selector and the decode 'thing' although 'thing' appears before 'selector'. Obviously, this can be done only if the encoding size of 'thing' is constant, which may not be the case.

(0003672)
shd01 (reporter)
2019-11-08 18:22

Ah yes, I see the issue. I guess this should be (1), report an error. And perhaps I should not have made this a "major".

(0003682)
gmamais (developer)
2019-11-17 09:41

fixed in the latest GitHub commit.
The ASN.1 compiler reports now an error.


- Issue History
Date Modified Username Field Change
2019-11-07 13:09 shd01 New Issue
2019-11-07 13:23 shd01 Note Added: 0003667
2019-11-07 13:23 shd01 Note Edited: 0003667 View Revisions
2019-11-07 13:24 shd01 Note Edited: 0003667 View Revisions
2019-11-07 13:24 shd01 Note Edited: 0003667 View Revisions
2019-11-07 13:25 shd01 Note Edited: 0003667 View Revisions
2019-11-07 13:30 shd01 Note Edited: 0003667 View Revisions
2019-11-07 13:30 shd01 Note Edited: 0003667 View Revisions
2019-11-07 13:34 shd01 Note Edited: 0003667 View Revisions
2019-11-07 13:35 shd01 Note Added: 0003668
2019-11-07 13:37 shd01 File Added: shit.acn
2019-11-07 13:37 maxime Assigned To

=> gmamais

2019-11-07 13:37 maxime Status

new => assigned

2019-11-07 13:37 shd01 Note Edited: 0003668 View Revisions
2019-11-07 17:10 gmamais Note Added: 0003670
2019-11-08 18:22 shd01 Note Added: 0003672
2019-11-17 09:41 gmamais Note Added: 0003682
2019-11-17 09:41 gmamais Status

assigned => resolved

2019-11-17 09:41 gmamais Resolution

open => fixed

2020-08-31 15:32 maxime Status

resolved => closed



Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker