88import enum
99import typing as t
1010
11- SCIKIT = True
12- try :
13- import skcriteria as skc
14- from skcriteria .madm import simple
15- except Exception :
16- SCIKIT = False
17-
18- from ..metrics import CallScore
11+ import skcriteria as skc
12+ from skcriteria .madm import simple
13+
14+ from ..metrics import CallScore , METRICS
1915from ..config import INTERESTING_PATTERNS , RISKY_GLIBC_CALL_PATTERNS
2016
2117# Type sig for a finalized list
@@ -81,11 +77,6 @@ def _rank_fuzzability(self, unranked: t.List[CallScore]) -> Fuzzability:
8177 This should be the tail call for run, as it produces the finalized results
8278 """
8379
84- # TODO: deprecate this.
85- if not SCIKIT :
86- return self ._rank_simple_fuzzability (unranked )
87-
88- # normalize
8980 nl_normalized = AnalysisBackend ._normalize (
9081 [score .natural_loops for score in unranked ]
9182 )
@@ -108,13 +99,7 @@ def _rank_fuzzability(self, unranked: t.List[CallScore]) -> Fuzzability:
10899 objectives ,
109100 weights = self .score_weights ,
110101 alternatives = names ,
111- criteria = [
112- "fuzz_friendly" ,
113- "sinks" ,
114- "loop" ,
115- "coverage" ,
116- "cyclomatic_complexity" ,
117- ],
102+ criteria = [metric .identifier for metric in METRICS [3 :8 ]],
118103 )
119104
120105 dec = simple .WeightedSumModel ()
@@ -135,19 +120,9 @@ def _rank_fuzzability(self, unranked: t.List[CallScore]) -> Fuzzability:
135120 sorted_results = [y for _ , y in sorted (zip (ranks , new_unranked ))]
136121 return sorted_results
137122
138- def _rank_simple_fuzzability (self , unranked : t .List [CallScore ]) -> Fuzzability :
139- nl_normalized = AnalysisBackend ._normalize (
140- [score .natural_loops for score in unranked ]
141- )
142- for score , new_nl in zip (unranked , nl_normalized ):
143- score .natural_loops = new_nl
144-
145- cc_normalized = AnalysisBackend ._normalize (
146- [score .cyclomatic_complexity for score in unranked ]
147- )
148- for score , new_cc in zip (unranked , cc_normalized ):
149- score .cyclomatic_complexity = new_cc
150-
123+ @staticmethod
124+ def _rank_simple_fuzzability (unranked : t .List [CallScore ]) -> Fuzzability :
125+ """Not used anymore."""
151126 return sorted (unranked , key = lambda obj : obj .simple_fuzzability , reverse = True )
152127
153128 @staticmethod
@@ -201,7 +176,8 @@ def is_toplevel_call(self, target: t.Any) -> bool:
201176 @abc .abstractmethod
202177 def risky_sinks (self , func : t .Any ) -> int :
203178 """
204- HEURISTIC
179+ FUZZABILITY HEURISTIC
180+
205181 Checks to see if one or more of the function's arguments is
206182 potentially user-controlled, and flows into an abusable call.
207183 """
@@ -215,7 +191,8 @@ def _is_risky_call(name: str) -> bool:
215191 @abc .abstractmethod
216192 def get_coverage_depth (self , func : t .Any ) -> int :
217193 """
218- HEURISTIC
194+ FUZZABILITY HEURISTIC
195+
219196 Calculates and returns a `CoverageReport` that highlights how much
220197 a fuzzer would ideally explore at different granularities.
221198 """
@@ -224,7 +201,8 @@ def get_coverage_depth(self, func: t.Any) -> int:
224201 @abc .abstractmethod
225202 def natural_loops (self , func : t .Any ) -> int :
226203 """
227- HEURISTIC
204+ FUZZABILITY HEURISTIC
205+
228206 Detection of loops is at a basic block level by checking the dominance frontier,
229207 which denotes the next successor the current block node will definitely reach. If the
230208 same basic block exists in the dominance frontier set, then that means the block will
@@ -235,7 +213,8 @@ def natural_loops(self, func: t.Any) -> int:
235213 @abc .abstractmethod
236214 def get_cyclomatic_complexity (self ) -> int :
237215 """
238- HEURISTIC
216+ FUZZABILITY HEURISTIC
217+
239218 Calculates the complexity of a given function using McCabe's metric. We do not
240219 account for connected components since we assume that the target is a singular
241220 connected component.
0 commit comments