From d57d84cff13251a17fa2410fca383fcffae389f6 Mon Sep 17 00:00:00 2001 From: Douglas R Miles Date: Sat, 25 Sep 2021 00:13:47 -0700 Subject: [PATCH 2/2] dmiles2 --- library/sandbox.pl | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/library/sandbox.pl b/library/sandbox.pl index dc9c3272b..d50cec963 100755 --- a/library/sandbox.pl +++ b/library/sandbox.pl @@ -75,19 +75,6 @@ safe_goal/1, which determines whether it is safe to call its argument. */ :- create_prolog_flag(no_sandbox, false, [type(boolean), keep(true)]). -<<<<<<< -======= - -do_permission_error(Operation, PermissionType, Culprit) :- - do_permission_error(Operation, PermissionType, Culprit, _). - -do_permission_error(_Operation, _PermissionType, _Culprit, _MoreInfo) :- current_prolog_flag(no_sandbox, true), !. -do_permission_error(Operation, PermissionType, Culprit, MoreInfo) :- - throw(error(permission_error(Operation, - PermissionType, - Culprit), - MoreInfo)). ->>>>>>> :- meta_predicate safe_goal(:), @@ -160,11 +147,7 @@ safe(V, _, Parents, _, _) :- nb_setval(sandbox_last_error, Error), throw(Error). -<<<<<<< -safe(_,_,_Parents,_Safe0,true):-current_prolog_flag(no_sandbox,true),!. -======= safe(_, _, _Parents, _Safe0, true):- current_prolog_flag(no_sandbox, true), !. ->>>>>>> safe(M:G, _, Parents, Safe0, Safe) :- !, @@ -187,8 +170,8 @@ safe(M:G, _, Parents, Safe0, Safe) :- ; memberchk(M:_, Parents) ) -> safe(G, M, Parents, Safe0, Safe) - ; do_permission_error(call, sandboxed, M:G, - sandbox(M:G, Parents)) + ; throw(error(permission_error(call, sandboxed, M:G), + sandbox(M:G, Parents))) ). safe(G, _, Parents, _, _) :- debugging(sandbox(show)), @@ -270,9 +253,8 @@ safe_clauses(G, M, Parents, Safe0, Safe) :- safe_clauses(G, M, [_|Parents], _, _) :- predicate_property(M:G, visible), !, - do_permission_error(call, sandboxed, G, - sandbox(M:G, Parents)). - + throw(error(permission_error(call, sandboxed, G), + sandbox(M:G, Parents))). safe_clauses(_, _, [G|Parents], _, _) :- throw(error(existence_error(procedure, G), sandbox(G, Parents))). @@ -284,8 +266,8 @@ known_module(M:_, _) :- !. known_module(_,_):- current_prolog_flag(no_sandbox, true), !, fail. known_module(M:G, Parents) :- - do_permission_error(call, sandboxed, M:G, - sandbox(M:G, Parents). + throw(error(permission_error(call, sandboxed, M:G), + sandbox(M:G, Parents))). add_iso_parent(G, Parents, Parents) :- is_control(G), @@ -473,10 +455,8 @@ verify_safe_declaration(Var) :- var(Var), !, instantiation_error(Var). -<<<<<<< -======= ->>>>>>> + verify_safe_declaration(_):- current_prolog_flag(no_sandbox, true), !. verify_safe_declaration(Module:Goal) :- !, @@ -491,14 +471,14 @@ verify_safe_declaration(Module:Goal) :- \+ predicate_property(Module:Goal, imported_from(_)), \+ predicate_property(Module:Goal, meta_predicate(_)) -> true - ; do_permission_error(declare, safe_goal, Module:Goal) + ; permission_error(declare, safe_goal, Module:Goal) ). verify_safe_declaration(Goal) :- must_be(callable, Goal), ( predicate_property(system:Goal, iso), \+ predicate_property(system:Goal, meta_predicate()) -> true - ; do_permission_error(declare, safe_goal, Goal) + ; permission_error(declare, safe_goal, Goal) ). ok_meta(system:assert(_)). @@ -1162,19 +1142,18 @@ prolog:sandbox_allowed_directive(_):- current_prolog_flag(no_sandbox, true), !. prolog:sandbox_allowed_directive(Directive) :- safe_directive(Directive), !. -prolog:sandbox_allowed_directive(_):- current_prolog_flag(no_sandbox, true), !. prolog:sandbox_allowed_directive(M:PredAttr) :- \+ prolog_load_context(module, M), !, debug(sandbox(directive), 'Cross-module directive', []), - do_permission_error(execute, sandboxed_directive, (:- M:PredAttr)). + permission_error(execute, sandboxed_directive, (:- M:PredAttr)). prolog:sandbox_allowed_directive(M:PredAttr) :- safe_pattr(PredAttr), !, PredAttr =.. [Attr, Preds], ( safe_pattr(Preds, Attr) -> true - ; do_permission_error(execute, sandboxed_directive, (:- M:PredAttr)) + ; permission_error(execute, sandboxed_directive, (:- M:PredAttr)) ). prolog:sandbox_allowed_directive(_:Directive) :- safe_source_directive(Directive), @@ -1228,7 +1207,7 @@ safe_pattr(M:G, Attr) :- prolog_load_context(module, M) -> true ; Goal =.. [Attr,M:G], - do_permission_error(directive, sandboxed, (:- Goal)) + permission_error(directive, sandboxed, (:- Goal)) ). safe_pattr(_, _). -- 2.33.0