[infra] Introduce "language" attribute in the project.yaml (#3297). (#3299)

* [infra] Introduce "language" attribute in the project.yaml (#3297).

* follow up

* enable the attribute for more projects

* trailing newline
This commit is contained in:
Max Moroz 2020-01-30 15:36:44 -08:00 committed by GitHub
parent 1405af8d0a
commit 7751ab5a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 46 additions and 13 deletions

View File

@ -30,12 +30,19 @@ libFuzzer command line interface as non-Go fuzz targets.
## Project files
The structure of the project directory in OSS-Fuzz repository doesn't differ for
projects written in Go. The project files have the following Go specific aspects.
projects written in Go. The project files have the following Go specific
aspects.
### project.yaml
For projects written in Go, we use only `libfuzzer` fuzzing engine and `address`
sanitizer.
The `language` attribute must be specified.
```yaml
language: go
```
The only supported fuzzing engine and sanitizer are `libfuzzer` and `address`,
respectively.
[Example](https://github.com/google/oss-fuzz/blob/356f2b947670b7eb33a1f535c71bc5c87a60b0d1/projects/syzkaller/project.yaml#L7):
```yaml

View File

@ -34,8 +34,8 @@ LATEST_REPORT_INFO_URL = ('/' + COVERAGE_BUCKET_NAME +
# Link where to upload code coverage report files to.
UPLOAD_URL_FORMAT = 'gs://' + COVERAGE_BUCKET_NAME + '/{project}/{type}/{date}'
# TODO(#2817): Support code coverage for Go projects.
GO_FUZZ_BUILD = 'go-fuzz-build -libfuzzer'
# Languages from project.yaml that have code coverage support.
LANGUAGES_WITH_COVERAGE_SUPPORT = ['c', 'cpp']
def skip_build(message):
@ -61,9 +61,11 @@ def get_build_steps(project_dir):
build_script_path = os.path.join(project_dir, 'build.sh')
if os.path.exists(build_script_path):
with open(build_script_path) as fh:
if GO_FUZZ_BUILD in fh.read():
skip_build('Project "%s" uses go-fuzz, coverage is not supported yet.' %
project_name)
if project_yaml['language'] not in LANGUAGES_WITH_COVERAGE_SUPPORT:
skip_build(('Project "{project_name}" is written in "{language}", '
'coverage is not supported yet.').format(
project_name=project_name,
language=project_yaml['language']))
dockerfile_path = os.path.join(project_dir, 'Dockerfile')
name = project_yaml['name']

View File

@ -58,6 +58,7 @@ def load_project_yaml(project_dir):
project_yaml.setdefault('run_tests', True)
project_yaml.setdefault('coverage_extra_args', '')
project_yaml.setdefault('labels', {})
project_yaml.setdefault('language', 'cpp')
return project_yaml

View File

@ -74,7 +74,7 @@ class ProjectYamlChecker:
SECTIONS_AND_CONSTANTS = {
'sanitizers': {'address', 'none', 'memory', 'undefined', 'dataflow'},
'architectures': {'i386', 'x86_64'},
'fuzzing_engines': {'afl', 'libfuzzer', 'honggfuzz', 'dataflow'}
'fuzzing_engines': {'afl', 'libfuzzer', 'honggfuzz', 'dataflow'},
}
# Note: this list must be updated when we allow new sections.
@ -89,8 +89,11 @@ class ProjectYamlChecker:
'sanitizers',
'vendor_ccs',
'view_restrictions',
'language',
]
LANGUAGES_SUPPORTED = ['c', 'cpp', 'go', 'rust', 'python']
# Note that some projects like boost only have auto-ccs. However, forgetting
# primary contact is probably a mistake.
REQUIRED_SECTIONS = ['primary_contact']
@ -108,8 +111,11 @@ class ProjectYamlChecker:
return True
checks = [
self.check_project_yaml_constants, self.check_required_sections,
self.check_valid_section_names, self.check_valid_emails
self.check_project_yaml_constants,
self.check_required_sections,
self.check_valid_section_names,
self.check_valid_emails,
self.check_valid_language,
]
for check_function in checks:
check_function()
@ -179,6 +185,16 @@ class ProjectYamlChecker:
if '@' not in email_address or '.' not in email_address:
self.error(email_address + ' is an invalid email address.')
def check_valid_language(self):
"""Check that the language specified is valid."""
language = self.data.get('language')
if not language:
return
if language not in self.LANGUAGES_SUPPORTED:
self.error('{language} is not supported ({supported}).'.format(
language=language, supported=self.LANGUAGES_SUPPORTED))
def _check_one_project_yaml(project_yaml_filename):
"""Do checks on the project.yaml file."""

View File

@ -7,3 +7,4 @@ fuzzing_engines:
- libfuzzer
sanitizers:
- address
language: go

View File

@ -1,7 +1,7 @@
homepage: "https://jsoniter.com"
primary_contact: "taowen@gmail.com"
auto_ccs : "p.antoine@catenacyber.fr"
language: go
fuzzing_engines:
- libfuzzer
sanitizers:

View File

@ -6,3 +6,4 @@ sanitizers:
- address
fuzzing_engines:
- libfuzzer
language: go

View File

@ -4,6 +4,7 @@ auto_ccs:
- "golang-fuzz@googlegroups.com"
- "mmoroz@chromium.org"
- "josharian@gmail.com"
language: go
sanitizers:
- address
fuzzing_engines:

View File

@ -1,7 +1,7 @@
homepage: "https://github.com/google/gonids"
primary_contact: "duane.security@gmail.com"
auto_ccs : "p.antoine@catenacyber.fr"
language: go
fuzzing_engines:
- libfuzzer
sanitizers:

View File

@ -4,3 +4,4 @@ fuzzing_engines:
- libfuzzer
sanitizers:
- address
language: go

View File

@ -4,3 +4,4 @@ fuzzing_engines:
- libfuzzer
sanitizers:
- address
language: go

View File

@ -4,6 +4,7 @@ auto_ccs:
- "andreyknvl@google.com"
- "mmoroz@chromium.org"
- "syzkaller@googlegroups.com"
language: go
fuzzing_engines:
- libfuzzer
sanitizers:

View File

@ -8,3 +8,4 @@ sanitizers:
- address
fuzzing_engines:
- libfuzzer
language: rust