diff --git a/libasn1fix/asn1fix_class.c b/libasn1fix/asn1fix_class.c index 5f124df3..b3bfae57 100644 --- a/libasn1fix/asn1fix_class.c +++ b/libasn1fix/asn1fix_class.c @@ -25,6 +25,25 @@ asn1f_class_access(arg_t *arg, asn1p_module_t *mod, asn1p_ref_t *ref) { errno = ESRCH; return NULL; } + if(ioclass->expr_type == A1TC_REFERENCE) { + ioclass = asn1f_lookup_symbol(arg, + ioclass->module, ioclass->reference); + if(ioclass == NULL) { + errno = ESRCH; + return NULL; + } + } + if(ioclass->expr_type != A1TC_CLASSDEF) { + if(!(ioclass->_mark & TM_BROKEN)) { + ioclass->_mark |= TM_BROKEN; + FATAL("Class field %s lookup at line %d in something that is not a class: %s at line %d", + asn1f_printable_reference(ref), ref->_lineno, + ioclass->Identifier, + ioclass->_lineno); + } + errno = EINVAL; + return NULL; + } classfield = asn1f_lookup_child(ioclass, ref->components[1].name); if(classfield == NULL) { diff --git a/tests/100-class-ref-OK.asn1 b/tests/100-class-ref-OK.asn1 new file mode 100644 index 00000000..e8c1f723 --- /dev/null +++ b/tests/100-class-ref-OK.asn1 @@ -0,0 +1,23 @@ + +-- OK: Everything is fine + +-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1) +-- .spelio.software.asn1c.test (9363.1.5.1) +-- .100 + +ModuleClassSample + { iso org(3) dod(6) internet (1) private(4) enterprise(1) + spelio(9363) software(1) asn1c(5) test(1) 100 } + DEFINITIONS ::= +BEGIN + + REF-ID ::= TYPE-IDENTIFIER + + RefID ::= SEQUENCE { + field REF-ID.&id, + params REF-ID.&Type + } + + SupportedReferences REF-ID ::= { ... } + +END diff --git a/tests/101-class-ref-SE.asn1 b/tests/101-class-ref-SE.asn1 new file mode 100644 index 00000000..373df7fe --- /dev/null +++ b/tests/101-class-ref-SE.asn1 @@ -0,0 +1,23 @@ + +-- SE: Semantic error + +-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1) +-- .spelio.software.asn1c.test (9363.1.5.1) +-- .101 + +ModuleClassMisUse + { iso org(3) dod(6) internet (1) private(4) enterprise(1) + spelio(9363) software(1) asn1c(5) test(1) 101 } + DEFINITIONS ::= +BEGIN + + NOTCLASS ::= SEQUENCE { ... } + + REF-ID ::= NOTCLASS + + RefID ::= SEQUENCE { + field REF-ID.&id, + params REF-ID.&Type + } + +END diff --git a/tests/102-class-ref-SE.asn1 b/tests/102-class-ref-SE.asn1 new file mode 100644 index 00000000..4f42240e --- /dev/null +++ b/tests/102-class-ref-SE.asn1 @@ -0,0 +1,22 @@ + +-- SE: Semantic error + +-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1) +-- .spelio.software.asn1c.test (9363.1.5.1) +-- .102 + +ModuleClassMisUse + { iso org(3) dod(6) internet (1) private(4) enterprise(1) + spelio(9363) software(1) asn1c(5) test(1) 102 } + DEFINITIONS ::= +BEGIN + + REF-ID ::= REF-ID2 + REF-ID2 ::= REF-ID + + RefID ::= SEQUENCE { + field REF-ID.&id, + params REF-ID.&Type + } + +END