Skip to content

Commit

Permalink
[infra] Introduce "language" attribute in the project.yaml (#3297).
Browse files Browse the repository at this point in the history
  • Loading branch information
Dor1s committed Jan 28, 2020
1 parent 96c9cd2 commit afe7277
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
13 changes: 10 additions & 3 deletions docs/getting-started/new-project-guide/go_lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions infra/gcb/build_and_run_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
# 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):
Expand All @@ -61,9 +61,9 @@ 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'] is 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']
Expand Down
1 change: 1 addition & 0 deletions infra/gcb/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
22 changes: 19 additions & 3 deletions infra/presubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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']
Expand All @@ -108,8 +111,11 @@ def do_checks(self):
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()
Expand Down Expand Up @@ -179,6 +185,16 @@ def check_valid_emails(self):
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."""
Expand Down
1 change: 1 addition & 0 deletions projects/mtail/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ fuzzing_engines:
- libfuzzer
sanitizers:
- address
language: go

0 comments on commit afe7277

Please sign in to comment.