Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylint: Fix pylint for analyses #2092

Merged
merged 2 commits into from
Feb 14, 2025
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
33 changes: 16 additions & 17 deletions src/fuzz_introspector/analyses/annotated_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@
import logging
import json

from typing import (Any, Dict, List, Optional)
from typing import (Any, Optional)

from fuzz_introspector import analysis
from fuzz_introspector import utils
from fuzz_introspector import cfg_load
from fuzz_introspector import json_report
from fuzz_introspector import html_helpers
from fuzz_introspector.datatypes import project_profile, fuzzer_profile, function_profile
from fuzz_introspector import (analysis, cfg_load, html_helpers, json_report,
utils)
from fuzz_introspector.datatypes import (project_profile, fuzzer_profile,
function_profile)

logger = logging.getLogger(name=__name__)


class FuzzAnnotatedCFG(analysis.AnalysisInterface):
"""Analysis for annotated configurations of fuzzing."""
name: str = "AnnotatedCFG"

def __init__(self) -> None:
logger.info("Creating annotated CFG")
self.json_string_result = ""
self.json_results: Dict[str, Any] = {}
self.json_results: dict[str, Any] = {}
self.dump_files = False

@classmethod
Expand All @@ -50,11 +49,11 @@ def set_json_string_result(self, json_string):

def analysis_func(self,
table_of_contents: html_helpers.HtmlTableOfContents,
tables: List[str],
tables: list[str],
proj_profile: project_profile.MergedProjectProfile,
profiles: List[fuzzer_profile.FuzzerProfile],
profiles: list[fuzzer_profile.FuzzerProfile],
basefolder: str, coverage_url: str,
conclusions: List[html_helpers.HTMLConclusion],
conclusions: list[html_helpers.HTMLConclusion],
out_dir: str) -> str:
"""
Creates the HTML of the calltree. Returns the HTML as a string.
Expand Down Expand Up @@ -92,17 +91,16 @@ def analysis_func(self,
proj_profile, callsite.dst_function_name)
if dst_fd is None:
dst_fd = self.get_profile_sourcefile_merged(
proj_profile,
"[%s].%s" % (callsite.dst_function_source_file,
callsite.dst_function_name))
proj_profile, (f'[{callsite.dst_function_source_file}]'
f'.{callsite.dst_function_name}'))

par_fd = self.get_profile_sourcefile_merged(
proj_profile, parent_callsite.dst_function_name)
if par_fd is None:
par_fd = self.get_profile_sourcefile_merged(
proj_profile,
"[%s].%s" % (parent_callsite.dst_function_source_file,
parent_callsite.dst_function_name))
(f'[{parent_callsite.dst_function_source_file}]'
f'.{parent_callsite.dst_function_name}'))

# To be a top level target a callsite should:
# 1.0) Not be in the fuzzer source file and one of the
Expand All @@ -115,7 +113,8 @@ def analysis_func(self,
if dst_fd is None:
continue

cond1 = dst_fd is not None and dst_fd.function_source_file != src_file
cond1 = (dst_fd is not None
and dst_fd.function_source_file != src_file)
cond2 = (par_fd is not None and par_fd.function_source_file
== src_file) or callsite.depth == 1
if (cond1 and cond2):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def get_json_string_result(self) -> str:

return json.dumps(self.json_results)

def set_json_string_result(self, string):
def set_json_string_result(self, json_string: str):
"""Store the result of this analyser as json string result
for further processing in a later time.

:param json_string: A json string variable storing the
processing result of the analyser for future use
:type json_string: str
"""
self.json_string_result = string
self.json_string_result = json_string

def set_flags(self, exclude_static_functions: bool,
only_referenced_functions: bool, only_header_functions: bool,
Expand Down
16 changes: 8 additions & 8 deletions src/fuzz_introspector/analyses/source_code_line_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import json
import logging

from typing import (Any, List, Dict)
from typing import Any

from fuzz_introspector import (analysis, html_helpers)

Expand All @@ -34,7 +34,7 @@ class SourceCodeLineAnalyser(analysis.AnalysisInterface):
name: str = 'SourceCodeLineAnalyser'

def __init__(self) -> None:
self.json_results: Dict[str, Any] = {}
self.json_results: dict[str, Any] = {}
self.json_string_result = ''

# Default value for standalone analysis
Expand Down Expand Up @@ -62,15 +62,15 @@ def get_json_string_result(self) -> str:
return self.json_string_result
return json.dumps(self.json_results)

def set_json_string_result(self, string):
def set_json_string_result(self, json_string: str):
"""Store the result of this analyser as json string result
for further processing in a later time.

:param json_string: A json string variable storing the
processing result of the analyser for future use
:type json_string: str
"""
self.json_string_result = string
self.json_string_result = json_string

def set_source_file_line(self, source_file: str, source_line: int):
"""Configure the source file and source line for this analyser."""
Expand All @@ -79,18 +79,18 @@ def set_source_file_line(self, source_file: str, source_line: int):

def analysis_func(self,
table_of_contents: html_helpers.HtmlTableOfContents,
tables: List[str],
tables: list[str],
proj_profile: project_profile.MergedProjectProfile,
profiles: List[fuzzer_profile.FuzzerProfile],
profiles: list[fuzzer_profile.FuzzerProfile],
basefolder: str, coverage_url: str,
conclusions: List[html_helpers.HTMLConclusion],
conclusions: list[html_helpers.HTMLConclusion],
out_dir: str) -> str:
self.standalone_analysis(proj_profile, profiles, out_dir)
return ''

def standalone_analysis(self,
proj_profile: project_profile.MergedProjectProfile,
profiles: List[fuzzer_profile.FuzzerProfile],
profiles: list[fuzzer_profile.FuzzerProfile],
out_dir: str) -> None:
super().standalone_analysis(proj_profile, profiles, out_dir)

Expand Down
Loading