Skip to content

Commit

Permalink
only erlang:send/2 on [a|sb]bcast if module 'erlang' is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
sg2342 authored and priestjim committed Dec 3, 2016
1 parent 69fdd93 commit 1b6518b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/gen_rpc_acceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,30 @@ waiting_for_data(info, {Driver,Socket,Data},
ok = DriverMod:activate_socket(Socket),
{keep_state_and_data, gen_rpc_helper:get_inactivity_timeout(?MODULE)};
{abcast, Name, Msg} ->
?log(debug, "event=abcast_received driver=~s socket=\"~s\" peer=\"~s\" process=~s message=\"~p\"",
[Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), Name, Msg]),
Msg = erlang:send(Name, Msg),
_Result = case check_if_module_allowed(erlang, Control, List) of
true ->
?log(debug, "event=abcast_received driver=~s socket=\"~s\" peer=\"~s\" process=~s message=\"~p\"",
[Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), Name, Msg]),
Msg = erlang:send(Name, Msg);
false ->
?log(debug, "event=request_not_allowed driver=~s socket=\"~s\" control=~s method=~s",
[Driver, gen_rpc_helper:socket_to_string(Socket), Control, abcast])
end,
ok = DriverMod:activate_socket(Socket),
{keep_state_and_data, gen_rpc_helper:get_inactivity_timeout(?MODULE)};
{sbcast, Name, Msg, Caller} ->
?log(debug, "event=sbcast_received driver=~s socket=\"~s\" peer=\"~s\" process=~s message=\"~p\"",
[Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), Name, Msg]),
Reply = case erlang:whereis(Name) of
undefined -> error;
Pid -> Msg = erlang:send(Pid, Msg), success
Reply = case check_if_module_allowed(erlang, Control, List) of
true ->
?log(debug, "event=sbcast_received driver=~s socket=\"~s\" peer=\"~s\" process=~s message=\"~p\"",
[Driver, gen_rpc_helper:socket_to_string(Socket), gen_rpc_helper:peer_to_string(Peer), Name, Msg]),
case erlang:whereis(Name) of
undefined -> error;
Pid -> Msg = erlang:send(Pid, Msg), success
end;
false ->
?log(debug, "event=request_not_allowed driver=~s socket=\"~s\" control=~s method=~s",
[Driver, gen_rpc_helper:socket_to_string(Socket), Control, sbcast]),
error
end,
ok = DriverMod:activate_socket(Socket),
waiting_for_data(info, {sbcast, Caller, Reply}, State);
Expand Down
2 changes: 2 additions & 0 deletions test/ct/local_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ rpc_module_whitelist(_Config) ->
rpc_module_blacklist(_Config) ->
{badrpc, unauthorized} = gen_rpc:call(?MASTER, os, timestamp),
{badrpc, unauthorized} = gen_rpc:call(?MASTER, erlang, node),
abcast = gen_rpc:abcast([?MASTER], init, {stop, stop}),
{[], [?MASTER]} = gen_rpc:sbcast([?MASTER], init, {stop, stop}),
60000 = gen_rpc:call(?MASTER, timer, seconds, [60]).

driver_stub(_Config) ->
Expand Down

0 comments on commit 1b6518b

Please sign in to comment.