Skip to content

Commit 0c615ae

Browse files
authored
Merge pull request #94 from python-security/fix_foddy_crash
Split up things more into different files
2 parents 41238d0 + bde8140 commit 0c615ae

22 files changed

+825
-922
lines changed

pyt/__main__.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
)
2121
from .github_search import scan_github, set_github_api_token
2222
from .interprocedural_cfg import interprocedural
23-
from .intraprocedural_cfg import intraprocedural
2423
from .lattice import print_lattice
2524
from .liveness import LivenessAnalysis
2625
from .project_handler import get_directory_modules, get_modules
@@ -106,8 +105,6 @@ def parse_args(args):
106105
' reaching definitions tainted version.',
107106
action='store_true')
108107

109-
parser.add_argument('-intra', '--intraprocedural-analysis',
110-
help='Run intraprocedural analysis.', action='store_true')
111108
parser.add_argument('-ppm', '--print-project-modules',
112109
help='Print project modules.', action='store_true')
113110

@@ -159,8 +156,18 @@ def parse_args(args):
159156

160157
def analyse_repo(github_repo, analysis_type):
161158
cfg_list = list()
162-
project_modules = get_modules(os.path.dirname(github_repo.path))
163-
intraprocedural(project_modules, cfg_list)
159+
directory = os.path.dirname(github_repo.path)
160+
project_modules = get_modules(directory)
161+
local_modules = get_directory_modules(directory)
162+
tree = generate_ast(github_repo.path, python_2=args.python_2)
163+
interprocedural_cfg = interprocedural(
164+
tree,
165+
project_modules,
166+
local_modules,
167+
github_repo.path
168+
)
169+
cfg_list.append(interprocedural_cfg)
170+
164171
initialize_constraint_table(cfg_list)
165172
analyse(cfg_list, analysis_type=analysis_type)
166173
vulnerability_log = find_vulnerabilities(cfg_list, analysis_type)
@@ -214,25 +221,23 @@ def main(command_line_args=sys.argv[1:]):
214221
tree = generate_ast(path, python_2=args.python_2)
215222

216223
cfg_list = list()
217-
218-
if args.intraprocedural_analysis:
219-
intraprocedural(project_modules, cfg_list)
220-
else:
221-
interprocedural_cfg = interprocedural(tree,
222-
project_modules,
223-
local_modules,
224-
path)
225-
cfg_list.append(interprocedural_cfg)
226-
framework_route_criteria = is_flask_route_function
227-
if args.adaptor:
228-
if args.adaptor.lower().startswith('e'):
229-
framework_route_criteria = is_function
230-
elif args.adaptor.lower().startswith('p'):
231-
framework_route_criteria = is_function_without_leading_
232-
elif args.adaptor.lower().startswith('d'):
233-
framework_route_criteria = is_django_view_function
234-
# Add all the route functions to the cfg_list
235-
FrameworkAdaptor(cfg_list, project_modules, local_modules, framework_route_criteria)
224+
interprocedural_cfg = interprocedural(
225+
tree,
226+
project_modules,
227+
local_modules,
228+
path
229+
)
230+
cfg_list.append(interprocedural_cfg)
231+
framework_route_criteria = is_flask_route_function
232+
if args.adaptor:
233+
if args.adaptor.lower().startswith('e'):
234+
framework_route_criteria = is_function
235+
elif args.adaptor.lower().startswith('p'):
236+
framework_route_criteria = is_function_without_leading_
237+
elif args.adaptor.lower().startswith('d'):
238+
framework_route_criteria = is_django_view_function
239+
# Add all the route functions to the cfg_list
240+
FrameworkAdaptor(cfg_list, project_modules, local_modules, framework_route_criteria)
236241

237242
initialize_constraint_table(cfg_list)
238243

pyt/alias_helper.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def as_alias_handler(alias_list):
1010
list_.append(alias.name)
1111
return list_
1212

13+
1314
def handle_aliases_in_calls(name, import_alias_mapping):
1415
"""Returns either None or the handled alias.
1516
Used in add_module.
@@ -26,6 +27,7 @@ def handle_aliases_in_calls(name, import_alias_mapping):
2627
return name.replace(key, val)
2728
return None
2829

30+
2931
def handle_aliases_in_init_files(name, import_alias_mapping):
3032
"""Returns either None or the handled alias.
3133
Used in add_module.
@@ -42,6 +44,7 @@ def handle_aliases_in_init_files(name, import_alias_mapping):
4244
return name.replace(val, key)
4345
return None
4446

47+
4548
def handle_fdid_aliases(module_or_package_name, import_alias_mapping):
4649
"""Returns either None or the handled alias.
4750
Used in add_module.
@@ -52,17 +55,19 @@ def handle_fdid_aliases(module_or_package_name, import_alias_mapping):
5255
return key
5356
return None
5457

58+
5559
def not_as_alias_handler(names_list):
5660
"""Returns a list of names ignoring any aliases."""
5761
list_ = list()
5862
for alias in names_list:
5963
list_.append(alias.name)
6064
return list_
6165

66+
6267
def retrieve_import_alias_mapping(names_list):
6368
"""Creates a dictionary mapping aliases to their respective name.
6469
import_alias_names is used in module_definitions.py and visit_Call"""
65-
import_alias_names = {}
70+
import_alias_names = dict()
6671

6772
for alias in names_list:
6873
if alias.asname:

0 commit comments

Comments
 (0)