Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
8ed484c5
Commit
8ed484c5
authored
Jun 25, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional fixes for safe_eval
parent
cc4129f6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
14 deletions
+17
-14
lib/ansible/utils/__init__.py
+17
-14
No files found.
lib/ansible/utils/__init__.py
View file @
8ed484c5
...
...
@@ -1040,22 +1040,23 @@ def safe_eval(expr, locals={}, include_exceptions=False):
# visitor class defined below.
SAFE_NODES
=
set
(
(
ast
.
Expression
,
ast
.
Add
,
ast
.
Attribute
,
ast
.
BinOp
,
ast
.
Call
,
ast
.
Compare
,
ast
.
Str
,
ast
.
List
,
ast
.
Tuple
,
ast
.
Dict
,
ast
.
Call
,
ast
.
Div
,
ast
.
Expression
,
ast
.
List
,
ast
.
Load
,
ast
.
BinOp
,
ast
.
UnaryOp
,
ast
.
Mult
,
ast
.
Num
,
ast
.
Name
,
ast
.
Add
,
ast
.
Str
,
ast
.
Sub
,
ast
.
Mult
,
ast
.
Div
,
ast
.
Tuple
,
ast
.
UnaryOp
,
)
)
...
...
@@ -1089,10 +1090,12 @@ def safe_eval(expr, locals={}, include_exceptions=False):
def
generic_visit
(
self
,
node
):
if
type
(
node
)
not
in
SAFE_NODES
:
raise
Exception
(
"invalid expression (
%
s)"
%
expr
)
super
(
CleansingNodeVisitor
,
self
)
.
generic_visit
(
node
)
def
visit_Call
(
self
,
call
):
if
call
.
func
.
id
not
in
CALL_WHITELIST
:
raise
Exception
(
"invalid function:
%
s"
%
call
.
func
.
id
)
elif
isinstance
(
node
,
ast
.
Call
):
if
not
isinstance
(
node
.
func
,
ast
.
Attribute
)
and
node
.
func
.
id
not
in
CALL_WHITELIST
:
raise
Exception
(
"invalid function:
%
s"
%
node
.
func
.
id
)
# iterate over all child nodes
for
child_node
in
ast
.
iter_child_nodes
(
node
):
super
(
CleansingNodeVisitor
,
self
)
.
visit
(
child_node
)
if
not
isinstance
(
expr
,
basestring
):
# already templated to a datastructure, perhaps?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment