aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-10-01 09:43:28 +0200
committerBjörn Gustavsson <[email protected]>2015-01-12 11:40:23 +0100
commitcb6a006acbcec5aae7cf94f163f101fb6c9d439a (patch)
tree87f69ec423db79a378eb09d21decbe60ddff3a86
parent6003a7c9d4319eba8eff7bfb8e4a73d3d1d38786 (diff)
downloadotp-cb6a006acbcec5aae7cf94f163f101fb6c9d439a.tar.gz
otp-cb6a006acbcec5aae7cf94f163f101fb6c9d439a.tar.bz2
otp-cb6a006acbcec5aae7cf94f163f101fb6c9d439a.zip
Check CLASS names for validity
Class names must start with an uppercase letter and only contain uppercase letters, digits, or hyphens. The parser will not allow class names that don't start with an uppercase letter, so we don't have to check that.
-rw-r--r--lib/asn1/src/asn1ct_check.erl20
-rw-r--r--lib/asn1/test/error_SUITE.erl16
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl
index a0253dba44..f1437597ec 100644
--- a/lib/asn1/src/asn1ct_check.erl
+++ b/lib/asn1/src/asn1ct_check.erl
@@ -438,7 +438,15 @@ do_checkp(S0, Name, #ptypedef{typespec=TypeSpec}=Type0) ->
checkc(S, Names) ->
check_fold(S, Names, fun do_checkc/3).
-do_checkc(S0, Name, Class0) ->
+do_checkc(S, Name, Class) ->
+ case is_classname(Name) of
+ false ->
+ return_asn1_error(S, Class, {illegal_class_name,Name});
+ true ->
+ do_checkc_1(S, Name, Class)
+ end.
+
+do_checkc_1(S0, Name, Class0) ->
{Class1,ClassSpec} =
case Class0 of
#classdef{} ->
@@ -456,6 +464,14 @@ do_checkc(S0, Name, Class0) ->
{error,Reason} ->
error({class,Reason,S})
end.
+
+%% is_classname(Atom) -> true|false.
+is_classname(Name) when is_atom(Name) ->
+ lists:all(fun($-) -> true;
+ (D) when $0 =< D, D =< $9 -> true;
+ (UC) when $A =< UC, UC =< $Z -> true;
+ (_) -> false
+ end, atom_to_list(Name)).
checko(S,[Name|Os],Acc,ExclO,ExclOS) ->
?dbg("Checking object ~p~n",[Name]),
@@ -6708,6 +6724,8 @@ asn1_error(S, Item, Error) ->
format_error({already_defined,Name,PrevLine}) ->
io_lib:format("the name ~p has already been defined at line ~p",
[Name,PrevLine]);
+format_error({illegal_class_name,Class}) ->
+ io_lib:format("the class name '~s' is illegal (it must start with an uppercase letter and only contain uppercase letters, digits, or hyphens)", [Class]);
format_error({illegal_instance_of,Class}) ->
io_lib:format("using INSTANCE OF on class '~s' is illegal, "
"because INSTANCE OF may only be used on the class TYPE-IDENTIFIER",
diff --git a/lib/asn1/test/error_SUITE.erl b/lib/asn1/test/error_SUITE.erl
index 1edd60f7c8..713f80cbee 100644
--- a/lib/asn1/test/error_SUITE.erl
+++ b/lib/asn1/test/error_SUITE.erl
@@ -19,7 +19,8 @@
-module(error_SUITE).
-export([suite/0,all/0,groups/0,
- already_defined/1,bitstrings/1,enumerated/1,
+ already_defined/1,bitstrings/1,
+ classes/1,enumerated/1,
imports/1,instance_of/1,integers/1,objects/1,
parameterization/1,values/1]).
@@ -34,6 +35,7 @@ groups() ->
[{p,parallel(),
[already_defined,
bitstrings,
+ classes,
enumerated,
imports,
instance_of,
@@ -94,6 +96,18 @@ bitstrings(Config) ->
]} = run(P, Config),
ok.
+classes(Config) ->
+ M = 'Classes',
+ P = {M,
+ <<"Classes DEFINITIONS AUTOMATIC TAGS ::= BEGIN\n"
+ " LowerCase ::= CLASS { &id INTEGER UNIQUE }\n"
+ "END\n">>},
+ {error,
+ [{structured_error,{M,2},asn1ct_check,{illegal_class_name,
+ 'LowerCase'}}
+ ]} = run(P, Config),
+ ok.
+
enumerated(Config) ->
M = 'Enumerated',
P = {M,