diff options
author | Björn Gustavsson <[email protected]> | 2014-12-18 08:23:58 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-01-12 12:22:59 +0100 |
commit | 09cd07962f7c64ec0ccef2ad655bf9977c154bf0 (patch) | |
tree | 62b067db0fbbac22c9b65c6152cf2b983bf7c6ea /lib | |
parent | ac5c60b0de2ef93a99f6c39f3e251f526f303964 (diff) | |
download | otp-09cd07962f7c64ec0ccef2ad655bf9977c154bf0.tar.gz otp-09cd07962f7c64ec0ccef2ad655bf9977c154bf0.tar.bz2 otp-09cd07962f7c64ec0ccef2ad655bf9977c154bf0.zip |
Improve error handling for illegal object definitions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asn1/src/asn1ct_check.erl | 23 | ||||
-rw-r--r-- | lib/asn1/test/error_SUITE.erl | 11 |
2 files changed, 25 insertions, 9 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index 6cbf9614cb..99392d6eaa 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -705,12 +705,14 @@ check_object(S,_ObjDef,#'Object'{classname=ClassRef,def=ObjectDef}) -> instantiate_po(S,ClassDef,Object,ArgList); #'Externalvaluereference'{} -> {_,Object} = get_referenced_type(S,ObjectDef), - check_object(S, Object, object_to_check(Object)); + check_object(S, Object, object_to_check(S, Object)); [] -> %% An object with no fields (parsed as a value). Def = {object,defaultsyntax,[]}, NewSettingList = check_objectdefn(S, Def, ClassDef), - #'Object'{def=NewSettingList} + #'Object'{def=NewSettingList}; + _ -> + asn1_error(S, illegal_object) end, Fields = (ClassDef#classdef.typespec)#objectclass.fields, Gen = gen_incl(S,NewObj#'Object'.def, Fields), @@ -973,12 +975,17 @@ traverse_seq_set_1([{'COMPONENTS OF', _} = CO0|Cs], Fun) -> traverse_seq_set_1([], _) -> []. -object_to_check(#typedef{typespec=ObjDef}) -> +object_to_check(_, #typedef{typespec=ObjDef}) -> ObjDef; -object_to_check(#valuedef{type=ClassName,value=ObjectRef}) -> +object_to_check(S, #valuedef{type=Class,value=ObjectRef}) -> %% If the object definition is parsed as an object the ClassName - %% is parsed as a type - #'Object'{classname=ClassName#type.def,def=ObjectRef}. + %% is parsed as a type. + case Class of + #type{def=#'Externaltypereference'{}=Def} -> + #'Object'{classname=Def,def=ObjectRef}; + _ -> + asn1_error(S, illegal_object) + end. check_referenced_object(S,ObjRef) when is_record(ObjRef,'Externalvaluereference')-> @@ -1182,7 +1189,7 @@ gen_incl1(S,Fields,[C|CFields]) -> check_object(S,TDef,TDef#typedef.typespec); ERef -> {_,T} = get_referenced_type(S,ERef), - check_object(S,T,object_to_check(T)) + check_object(S, T, object_to_check(S, T)) end, case gen_incl(S,ObjDef#'Object'.def, ClassFields) of @@ -1413,7 +1420,7 @@ match_syntax_type(_S, {fixedtypevaluesetfield,Name,#type{},_}, Any) -> {match,[{Name,Any}]}; match_syntax_type(S, {objectfield,Name,_,_,_}, #'Externalvaluereference'{}=Ref) -> {M,Obj} = get_referenced_type(S, Ref), - check_object(S, Obj, object_to_check(Obj)), + check_object(S, Obj, object_to_check(S, Obj)), {match,[{Name,Ref#'Externalvaluereference'{module=M}}]}; match_syntax_type(S, {objectfield,Name,Class,_,_}, {object,_,_}=ObjDef) -> InlinedObjName = list_to_atom(lists:concat([S#state.tname, diff --git a/lib/asn1/test/error_SUITE.erl b/lib/asn1/test/error_SUITE.erl index c6b6e9dffc..a9893b91cc 100644 --- a/lib/asn1/test/error_SUITE.erl +++ b/lib/asn1/test/error_SUITE.erl @@ -285,6 +285,9 @@ objects(Config) -> " InvalidSet CL ::= { obj1 }\n" " obj5 CL ::= {}\n" " ErrSet ::= PT{ {PT{inst}}}\n" + " obj6 CL ::= 7\n" + " obj7 CL ::= int\n" + " obj8 NON-CLASS ::= { &id 1 }\n" " CL ::= CLASS {\n" " &code INTEGER UNIQUE,\n" @@ -303,6 +306,9 @@ objects(Config) -> " PT{SMALL:Small} ::= SEQUENCE { a SMALL.&code ({Small}) }\n" " inst SMALL ::= {&code 42, &i 4711}\n" + + " int INTEGER ::= 42\n" + " NON-CLASS ::= SEQUENCE { a BOOLEAN }\n" "END\n">>}, {error, [ @@ -321,7 +327,10 @@ objects(Config) -> {missing_mandatory_fields, ['Data','Set','VarTypeValue',code,enum,object, vartypevalue],obj5}}, - {structured_error,{M,8},asn1ct_check,invalid_objectset} + {structured_error,{M,8},asn1ct_check,invalid_objectset}, + {structured_error,{M,9},asn1ct_check,illegal_object}, + {structured_error,{M,10},asn1ct_check,illegal_object}, + {structured_error,{M,11},asn1ct_check,illegal_object} ] } = run(P, Config), ok. |