aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-09-04 04:40:54 +0200
committerBjörn Gustavsson <[email protected]>2018-09-12 14:19:04 +0200
commit0975c1e3fc4e05a9b4eb12ce91e240cdebc28d04 (patch)
tree6d6a5ea66ee8347f9bf9ede2c992363283e2ece3
parentd96778ad4631d649fe64716e07e4f3a2ba9c681d (diff)
downloadotp-0975c1e3fc4e05a9b4eb12ce91e240cdebc28d04.tar.gz
otp-0975c1e3fc4e05a9b4eb12ce91e240cdebc28d04.tar.bz2
otp-0975c1e3fc4e05a9b4eb12ce91e240cdebc28d04.zip
beam_validator: Validate the literals in select_val
-rw-r--r--lib/compiler/src/beam_validator.erl25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl
index d5833875ff..9fa55c5b4c 100644
--- a/lib/compiler/src/beam_validator.erl
+++ b/lib/compiler/src/beam_validator.erl
@@ -648,10 +648,12 @@ valfun_4({set_tuple_element,Src,Tuple,I}, Vst) ->
%% Match instructions.
valfun_4({select_val,Src,{f,Fail},{list,Choices}}, Vst0) ->
assert_term(Src, Vst0),
+ assert_choices(Choices),
Vst = branch_state(Fail, Vst0),
kill_state(select_val_branches(Src, Choices, Vst));
valfun_4({select_tuple_arity,Tuple,{f,Fail},{list,Choices}}, Vst) ->
assert_type(tuple, Tuple, Vst),
+ assert_arities(Choices),
TupleType = case get_term_type(Tuple, Vst) of
{fragile,TupleType0} -> TupleType0;
TupleType0 -> TupleType0
@@ -1088,6 +1090,29 @@ prune_x_regs(Live, #vst{current=St0}=Vst)
St = St0#st{x=gb_trees:from_orddict(Xs),defs=Defs,aliases=Aliases},
Vst#vst{current=St}.
+%% All choices in a select_val list must be integers, floats, or atoms.
+%% All must be of the same type.
+assert_choices([{Tag,_},{f,_}|T]) ->
+ if
+ Tag =:= atom; Tag =:= float; Tag =:= integer ->
+ assert_choices_1(T, Tag);
+ true ->
+ error(bad_select_list)
+ end;
+assert_choices([]) -> ok.
+
+assert_choices_1([{Tag,_},{f,_}|T], Tag) ->
+ assert_choices_1(T, Tag);
+assert_choices_1([_,{f,_}|_], _Tag) ->
+ error(bad_select_list);
+assert_choices_1([], _Tag) -> ok.
+
+assert_arities([Arity,{f,_}|T]) when is_integer(Arity) ->
+ assert_arities(T);
+assert_arities([]) -> ok;
+assert_arities(_) -> error(bad_tuple_arity_list).
+
+
%%%
%%% Floating point checking.
%%%