Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions pyt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
)
from .github_search import scan_github, set_github_api_token
from .interprocedural_cfg import interprocedural
from .intraprocedural_cfg import intraprocedural
from .lattice import print_lattice
from .liveness import LivenessAnalysis
from .project_handler import get_directory_modules, get_modules
Expand Down Expand Up @@ -106,8 +105,6 @@ def parse_args(args):
' reaching definitions tainted version.',
action='store_true')

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

Expand Down Expand Up @@ -159,8 +156,18 @@ def parse_args(args):

def analyse_repo(github_repo, analysis_type):
cfg_list = list()
project_modules = get_modules(os.path.dirname(github_repo.path))
intraprocedural(project_modules, cfg_list)
directory = os.path.dirname(github_repo.path)
project_modules = get_modules(directory)
local_modules = get_directory_modules(directory)
tree = generate_ast(github_repo.path, python_2=args.python_2)
interprocedural_cfg = interprocedural(
tree,
project_modules,
local_modules,
github_repo.path
)
cfg_list.append(interprocedural_cfg)

initialize_constraint_table(cfg_list)
analyse(cfg_list, analysis_type=analysis_type)
vulnerability_log = find_vulnerabilities(cfg_list, analysis_type)
Expand Down Expand Up @@ -214,25 +221,23 @@ def main(command_line_args=sys.argv[1:]):
tree = generate_ast(path, python_2=args.python_2)

cfg_list = list()

if args.intraprocedural_analysis:
intraprocedural(project_modules, cfg_list)
else:
interprocedural_cfg = interprocedural(tree,
project_modules,
local_modules,
path)
cfg_list.append(interprocedural_cfg)
framework_route_criteria = is_flask_route_function
if args.adaptor:
if args.adaptor.lower().startswith('e'):
framework_route_criteria = is_function
elif args.adaptor.lower().startswith('p'):
framework_route_criteria = is_function_without_leading_
elif args.adaptor.lower().startswith('d'):
framework_route_criteria = is_django_view_function
# Add all the route functions to the cfg_list
FrameworkAdaptor(cfg_list, project_modules, local_modules, framework_route_criteria)
interprocedural_cfg = interprocedural(
tree,
project_modules,
local_modules,
path
)
cfg_list.append(interprocedural_cfg)
framework_route_criteria = is_flask_route_function
if args.adaptor:
if args.adaptor.lower().startswith('e'):
framework_route_criteria = is_function
elif args.adaptor.lower().startswith('p'):
framework_route_criteria = is_function_without_leading_
elif args.adaptor.lower().startswith('d'):
framework_route_criteria = is_django_view_function
# Add all the route functions to the cfg_list
FrameworkAdaptor(cfg_list, project_modules, local_modules, framework_route_criteria)

initialize_constraint_table(cfg_list)

Expand Down
7 changes: 6 additions & 1 deletion pyt/alias_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def as_alias_handler(alias_list):
list_.append(alias.name)
return list_


def handle_aliases_in_calls(name, import_alias_mapping):
"""Returns either None or the handled alias.
Used in add_module.
Expand All @@ -26,6 +27,7 @@ def handle_aliases_in_calls(name, import_alias_mapping):
return name.replace(key, val)
return None


def handle_aliases_in_init_files(name, import_alias_mapping):
"""Returns either None or the handled alias.
Used in add_module.
Expand All @@ -42,6 +44,7 @@ def handle_aliases_in_init_files(name, import_alias_mapping):
return name.replace(val, key)
return None


def handle_fdid_aliases(module_or_package_name, import_alias_mapping):
"""Returns either None or the handled alias.
Used in add_module.
Expand All @@ -52,17 +55,19 @@ def handle_fdid_aliases(module_or_package_name, import_alias_mapping):
return key
return None


def not_as_alias_handler(names_list):
"""Returns a list of names ignoring any aliases."""
list_ = list()
for alias in names_list:
list_.append(alias.name)
return list_


def retrieve_import_alias_mapping(names_list):
"""Creates a dictionary mapping aliases to their respective name.
import_alias_names is used in module_definitions.py and visit_Call"""
import_alias_names = {}
import_alias_names = dict()

for alias in names_list:
if alias.asname:
Expand Down
Loading