[infra] Add block listed target name logic from ClusterFuzz (#6538)

* [infra] Add block listed target name logic from ClusterFuzz
This commit is contained in:
Fabian Meumertzheim 2021-09-29 17:43:40 +02:00 committed by GitHub
parent ab547f1881
commit 5b4bd94235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -25,7 +25,8 @@ import helper
ALLOWED_FUZZ_TARGET_EXTENSIONS = ['', '.exe']
FUZZ_TARGET_SEARCH_STRING = 'LLVMFuzzerTestOneInput'
VALID_TARGET_NAME = re.compile(r'^[a-zA-Z0-9_-]+$')
VALID_TARGET_NAME_REGEX = re.compile(r'^[a-zA-Z0-9_-]+$')
BLOCKLISTED_TARGET_NAME_REGEX = re.compile(r'^(jazzer_driver.*)$')
# Location of google cloud storage for latest OSS-Fuzz builds.
GCS_BASE_URL = 'https://storage.googleapis.com/'
@ -118,11 +119,17 @@ def is_fuzz_target_local(file_path):
Copied from clusterfuzz src/python/bot/fuzzers/utils.py
with slight modifications.
"""
# pylint: disable=too-many-return-statements
filename, file_extension = os.path.splitext(os.path.basename(file_path))
if not VALID_TARGET_NAME.match(filename):
if not VALID_TARGET_NAME_REGEX.match(filename):
# Check fuzz target has a valid name (without any special chars).
return False
if BLOCKLISTED_TARGET_NAME_REGEX.match(filename):
# Check fuzz target an explicitly disallowed name (e.g. binaries used for
# jazzer-based targets).
return False
if file_extension not in ALLOWED_FUZZ_TARGET_EXTENSIONS:
# Ignore files with disallowed extensions (to prevent opening e.g. .zips).
return False