Skip to content

Commit 48a868a

Browse files
author
Simon Siegert
committed
Enable printing error statistics to stderr
1 parent 4194453 commit 48a868a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

bin/py_find_injection.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/usr/bin/env python
22

3+
from __future__ import print_function
4+
35
import argparse
46
import ast
57
import sys
68

9+
710
version_info = (0, 1, 2)
811
__version__ = '.'.join(map(str, version_info))
912

13+
1014
def stringify(node):
1115
if isinstance(node, ast.Name):
1216
return node.id
@@ -61,9 +65,9 @@ def __init__(self, filename, *args, **kwargs):
6165
def check_execute(self, node):
6266
if isinstance(node, ast.BinOp):
6367
if isinstance(node.op, ast.Mod):
64-
return IllegalLine('string interpolation of SQL query', node, self.filename)
68+
return IllegalLine('String interpolation of SQL query', node, self.filename)
6569
elif isinstance(node.op, ast.Add):
66-
return IllegalLine('string concatenation of SQL query', node, self.filename)
70+
return IllegalLine('String concatenation of SQL query', node, self.filename)
6771
elif isinstance(node, ast.Call):
6872
if isinstance(node.func, ast.Attribute):
6973
if node.func.attr == 'format':
@@ -86,7 +90,7 @@ def visit_Call(self, node):
8690
except IndexError:
8791
pass
8892
elif function_name.lower() == 'eval':
89-
self.errors.append(IllegalLine('eval() is just generally evil', node, self.filename))
93+
self.errors.append(IllegalLine('eval() is generally dangerous', node, self.filename))
9094
self.generic_visit(node)
9195

9296
def visit(self, node):
@@ -132,10 +136,10 @@ def main():
132136
for fname in args.files:
133137
these_errors = check(fname)
134138
if these_errors:
135-
print '\n'.join(str(e) for e in these_errors)
139+
print('\n'.join(str(e) for e in these_errors))
136140
errors.extend(these_errors)
137141
if errors:
138-
print '%d total errors' % len(errors)
142+
print('%d total errors' % len(errors), file=sys.stderr)
139143
return 1
140144
else:
141145
return 0

0 commit comments

Comments
 (0)