Skip to content

Instantly share code, notes, and snippets.

@yurrriq
Created August 14, 2015 07:59
Show Gist options
  • Select an option

  • Save yurrriq/d3d1a3d435685b13f2fa to your computer and use it in GitHub Desktop.

Select an option

Save yurrriq/d3d1a3d435685b13f2fa to your computer and use it in GitHub Desktop.
Testing LFE shell in restricted mode

Testing LFE shell in restricted mode

restricted.erl

-module(restricted).
-export ([non_local_allowed/3]).

%% Disallow lists:seq(...).
non_local_allowed({lists, seq}, _A, _State) -> {false, _State};
non_local_allowed({_M, _F}, _A, _State)     -> {true,  _State}.
erlc restricted.erl

Start an Erlang restricted_shell with custom blacklist (restricted.erl)

erl -stdlib restricted_shell restricted
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Restricted Eshell V7.0  (abort with ^G)
1> lists:seq(1, 10).
** exception exit: restricted shell does not allow lists:seq(1,10)

The lists:seq fails, as desired.

Attempt to start an LFE restricted_shell with custom blacklist (restricted.erl)

erl -stdlib restricted_shell restricted
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

LFE Shell V7.0 (abort with ^G)
> (lists:seq 1 10)
(1 2 3 4 5 6 7 8 9 10)

The lists:seq succeeds, undesirably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment