33
33
from experiment import benchmark as benchmarklib
34
34
from experiment import oss_fuzz_checkout
35
35
36
+ logger = logging .getLogger (__name__ )
37
+
36
38
T = TypeVar ('T' , str , list , dict , int ) # Generic type.
37
39
38
40
TIMEOUT = 45
@@ -96,7 +98,6 @@ def set_introspector_endpoints(endpoint):
96
98
INTROSPECTOR_FUNCTION_WITH_MATCHING_RETURN_TYPE
97
99
98
100
INTROSPECTOR_ENDPOINT = endpoint
99
- logging .info ('Fuzz Introspector endpoint set to %s' , INTROSPECTOR_ENDPOINT )
100
101
101
102
INTROSPECTOR_CFG = f'{ INTROSPECTOR_ENDPOINT } /annotated-cfg'
102
103
INTROSPECTOR_ORACLE_FAR_REACH = (
@@ -139,7 +140,7 @@ def _query_introspector(api: str, params: dict) -> Optional[requests.Response]:
139
140
try :
140
141
resp = requests .get (api , params , timeout = TIMEOUT )
141
142
if not resp .ok :
142
- logging .error (
143
+ logger .error (
143
144
'Failed to get data from FI:\n '
144
145
'%s\n '
145
146
'-----------Response received------------\n '
@@ -150,19 +151,19 @@ def _query_introspector(api: str, params: dict) -> Optional[requests.Response]:
150
151
return resp
151
152
except requests .exceptions .Timeout as err :
152
153
if attempt_num == MAX_RETRY :
153
- logging .error (
154
+ logger .error (
154
155
'Failed to get data from FI due to timeout, max retry exceeded:\n '
155
156
'%s\n '
156
157
'Error: %s' , _construct_url (api , params ), err )
157
158
break
158
159
delay = 5 * 2 ** attempt_num + random .randint (1 , 10 )
159
- logging .warning (
160
+ logger .warning (
160
161
'Failed to get data from FI due to timeout on attempt %d:\n '
161
162
'%s\n '
162
163
'retry in %ds...' , attempt_num , _construct_url (api , params ), delay )
163
164
time .sleep (delay )
164
165
except requests .exceptions .RequestException as err :
165
- logging .error (
166
+ logger .error (
166
167
'Failed to get data from FI due to unexpected error:\n '
167
168
'%s\n '
168
169
'Error: %s' , _construct_url (api , params ), err )
@@ -180,7 +181,7 @@ def _get_data(resp: Optional[requests.Response], key: str,
180
181
try :
181
182
data = resp .json ()
182
183
except requests .exceptions .InvalidJSONError :
183
- logging .error (
184
+ logger .error (
184
185
'Unable to parse response from FI:\n '
185
186
'%s\n '
186
187
'-----------Response received------------\n '
@@ -193,9 +194,9 @@ def _get_data(resp: Optional[requests.Response], key: str,
193
194
if content :
194
195
return content
195
196
196
- logging .error ('Failed to get %s from FI:\n '
197
- '%s\n '
198
- '%s' , key , resp .url , data )
197
+ logger .error ('Failed to get %s from FI:\n '
198
+ '%s\n '
199
+ '%s' , key , resp .url , data )
199
200
return default_value
200
201
201
202
@@ -243,7 +244,7 @@ def query_introspector_for_targets(project, target_oracle) -> list[Dict]:
243
244
"""Queries introspector for target functions."""
244
245
query_func = get_oracle_dict ().get (target_oracle , None )
245
246
if not query_func :
246
- logging .error ('No such oracle "%s"' , target_oracle )
247
+ logger .error ('No such oracle "%s"' , target_oracle )
247
248
sys .exit (1 )
248
249
return query_func (project )
249
250
@@ -453,7 +454,7 @@ def _get_raw_return_type(function: dict, project: str) -> str:
453
454
"""Returns the raw function type."""
454
455
return_type = function .get ('return-type' ) or function .get ('return_type' , '' )
455
456
if not return_type :
456
- logging .error (
457
+ logger .error (
457
458
'Missing return type in project: %s\n '
458
459
' raw_function_name: %s' , project ,
459
460
get_raw_function_name (function , project ))
@@ -475,8 +476,8 @@ def get_raw_function_name(function: dict, project: str) -> str:
475
476
raw_name = (function .get ('raw-function-name' ) or
476
477
function .get ('raw_function_name' , '' ))
477
478
if not raw_name :
478
- logging .error ('No raw function name in project: %s for function: %s' ,
479
- project , function )
479
+ logger .error ('No raw function name in project: %s for function: %s' ,
480
+ project , function )
480
481
return raw_name
481
482
482
483
@@ -485,7 +486,7 @@ def _get_clean_arg_types(function: dict, project: str) -> list[str]:
485
486
raw_arg_types = (function .get ('arg-types' ) or
486
487
function .get ('function_arguments' , []))
487
488
if not raw_arg_types :
488
- logging .error (
489
+ logger .error (
489
490
'Missing argument types in project: %s\n '
490
491
' raw_function_name: %s' , project ,
491
492
get_raw_function_name (function , project ))
@@ -521,7 +522,7 @@ def _get_arg_names(function: dict, project: str, language: str) -> list[str]:
521
522
arg_names = (function .get ('arg-names' ) or
522
523
function .get ('function_argument_names' , []))
523
524
if not arg_names :
524
- logging .error (
525
+ logger .error (
525
526
'Missing argument names in project: %s\n '
526
527
' raw_function_name: %s' , project ,
527
528
get_raw_function_name (function , project ))
@@ -535,7 +536,7 @@ def get_function_signature(function: dict, project: str) -> str:
535
536
# For JVM projects, the full function signature are the raw function name
536
537
return get_raw_function_name (function , project )
537
538
if not function_signature :
538
- logging .error (
539
+ logger .error (
539
540
'Missing function signature in project: %s\n '
540
541
' raw_function_name: %s' , project ,
541
542
get_raw_function_name (function , project ))
@@ -565,7 +566,7 @@ def _select_top_functions_from_oracle(project: str, limit: int,
565
566
if target_oracle not in target_oracles :
566
567
return OrderedDict ()
567
568
568
- logging .info ('Extracting functions using oracle %s.' , target_oracle )
569
+ logger .info ('Extracting functions using oracle %s.' , target_oracle )
569
570
functions = query_introspector_for_targets (project , target_oracle )[:limit ]
570
571
571
572
return OrderedDict ((func ['function_signature' ], func ) for func in functions )
@@ -650,7 +651,7 @@ def populate_benchmarks_using_introspector(project: str, language: str,
650
651
functions = _select_functions_from_oracles (project , limit , target_oracles )
651
652
652
653
if not functions :
653
- logging .error ('No functions found using the oracles: %s' , target_oracles )
654
+ logger .error ('No functions found using the oracles: %s' , target_oracles )
654
655
return []
655
656
656
657
if language == 'jvm' :
@@ -671,13 +672,13 @@ def populate_benchmarks_using_introspector(project: str, language: str,
671
672
harnesses , interesting = result
672
673
harness = pick_one (harnesses )
673
674
if not harness :
674
- logging .error ('No fuzz target found in project %s.' , project )
675
+ logger .error ('No fuzz target found in project %s.' , project )
675
676
return []
676
- logging .info ('Fuzz target file found for project %s: %s' , project , harness )
677
+ logger .info ('Fuzz target file found for project %s: %s' , project , harness )
677
678
678
679
target_name = get_target_name (project , harness )
679
- logging .info ('Fuzz target binary found for project %s: %s' , project ,
680
- target_name )
680
+ logger .info ('Fuzz target binary found for project %s: %s' , project ,
681
+ target_name )
681
682
682
683
potential_benchmarks = []
683
684
for function in functions :
@@ -699,17 +700,17 @@ def populate_benchmarks_using_introspector(project: str, language: str,
699
700
# stored as <SOURCE_BASE>/a/b/c/d.java
700
701
src_file = f'{ filename .replace ("." , "/" )} .java'
701
702
if src_file not in src_path_list :
702
- logging .error ('error: %s %s' , filename , interesting .keys ())
703
+ logger .error ('error: %s %s' , filename , interesting .keys ())
703
704
continue
704
705
elif filename not in [os .path .basename (i ) for i in interesting .keys ()]:
705
706
# TODO: Bazel messes up paths to include "/proc/self/cwd/..."
706
- logging .error ('error: %s %s' , filename , interesting .keys ())
707
+ logger .error ('error: %s %s' , filename , interesting .keys ())
707
708
continue
708
709
709
710
function_signature = get_function_signature (function , project )
710
711
if not function_signature :
711
712
continue
712
- logging .info ('Function signature to fuzz: %s' , function_signature )
713
+ logger .info ('Function signature to fuzz: %s' , function_signature )
713
714
potential_benchmarks .append (
714
715
benchmarklib .Benchmark ('cli' ,
715
716
project ,
@@ -728,7 +729,7 @@ def populate_benchmarks_using_introspector(project: str, language: str,
728
729
729
730
if len (potential_benchmarks ) >= (limit * len (target_oracles )):
730
731
break
731
- print ("Length of potential targets: %d" % (len (potential_benchmarks )))
732
+ logger . info ("Length of potential targets: %d" % (len (potential_benchmarks )))
732
733
733
734
return potential_benchmarks
734
735
@@ -761,7 +762,7 @@ def _identify_latest_report(project_name: str):
761
762
if summaries :
762
763
return ('https://storage.googleapis.com/oss-fuzz-introspector/'
763
764
f'{ summaries [- 1 ]} ' )
764
- logging .error ('Error: %s has no summary.' , project_name )
765
+ logger .error ('Error: %s has no summary.' , project_name )
765
766
return None
766
767
767
768
@@ -799,14 +800,14 @@ def get_project_funcs(project_name: str) -> Dict[str, List[Dict]]:
799
800
from FuzzIntrospector."""
800
801
introspector_json_report = _extract_introspector_report (project_name )
801
802
if introspector_json_report is None :
802
- logging .error ('No fuzz introspector report is found.' )
803
+ logger .error ('No fuzz introspector report is found.' )
803
804
return {}
804
805
805
806
if introspector_json_report .get ('analyses' ) is None :
806
- logging .error ('Error: introspector_json_report has no "analyses"' )
807
+ logger .error ('Error: introspector_json_report has no "analyses"' )
807
808
return {}
808
809
if introspector_json_report .get ('analyses' ).get ('AnnotatedCFG' ) is None :
809
- logging .error (
810
+ logger .error (
810
811
'Error: introspector_json_report["analyses"] has no "AnnotatedCFG"' )
811
812
return {}
812
813
@@ -885,8 +886,8 @@ def _parse_arguments() -> argparse.Namespace:
885
886
oss_fuzz_checkout .clone_oss_fuzz ()
886
887
oss_fuzz_checkout .postprocess_oss_fuzz ()
887
888
except subprocess .CalledProcessError as e :
888
- logging .error ('Failed to prepare OSS-Fuzz directory for project %s: %s' ,
889
- args .project , e )
889
+ logger .error ('Failed to prepare OSS-Fuzz directory for project %s: %s' ,
890
+ args .project , e )
890
891
cur_project_language = oss_fuzz_checkout .get_project_language (args .project )
891
892
benchmarks = populate_benchmarks_using_introspector (args .project ,
892
893
cur_project_language ,
@@ -895,5 +896,5 @@ def _parse_arguments() -> argparse.Namespace:
895
896
if benchmarks :
896
897
benchmarklib .Benchmark .to_yaml (benchmarks , args .out )
897
898
else :
898
- logging .error ('Nothing found for %s' , args .project )
899
+ logger .error ('Nothing found for %s' , args .project )
899
900
sys .exit (1 )
0 commit comments