예제 #1
0
 def test_invalid_commit_sha(self):
     """Tests building fuzzers with invalid commit SHA."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         with self.assertRaises(AssertionError):
             cifuzz.build_fuzzers(EXAMPLE_PROJECT,
                                  'oss-fuzz',
                                  tmp_dir,
                                  commit_sha='')
예제 #2
0
def main():
    """Build OSS-Fuzz project's fuzzers for CI tools.
  This script is used to kick off the Github Actions CI tool. It is the
  entrypoint of the Dockerfile in this directory. This action can be added to
  any OSS-Fuzz project's workflow that uses Github.

  Note: The resulting clusterfuzz binaries of this build are placed in
  the directory: ${GITHUB_WORKSPACE}/out

  Required environment variables:
    OSS_FUZZ_PROJECT_NAME: The name of OSS-Fuzz project.
    GITHUB_REPOSITORY: The name of the Github repo that called this script.
    GITHUB_SHA: The commit SHA that triggered this script.
    GITHUB_REF: The pull request reference that triggered this script.
    GITHUB_EVENT_NAME: The name of the hook event that triggered this script.
    GITHUB_WORKSPACE: The shared volume directory where input artifacts are.

  Returns:
    0 on success or 1 on Failure.
  """
    oss_fuzz_project_name = os.environ.get('OSS_FUZZ_PROJECT_NAME')
    github_repo_name = os.path.basename(os.environ.get('GITHUB_REPOSITORY'))
    pr_ref = os.environ.get('GITHUB_REF')
    commit_sha = os.environ.get('GITHUB_SHA')
    event = os.environ.get('GITHUB_EVENT_NAME')
    workspace = os.environ.get('GITHUB_WORKSPACE')

    # Check if failures should not be reported.
    dry_run = (os.environ.get('DRY_RUN').lower() == 'true')

    # The default return code when an error occurs.
    returncode = 1
    if dry_run:
        # Sets the default return code on error to success.
        returncode = 0

    if not workspace:
        logging.error(
            'This script needs to be run in the Github action context.')
        return returncode

    if event == 'push' and not cifuzz.build_fuzzers(oss_fuzz_project_name,
                                                    github_repo_name,
                                                    workspace,
                                                    commit_sha=commit_sha):
        logging.error('Error building fuzzers for project %s with commit %s.',
                      oss_fuzz_project_name, commit_sha)
        return returncode
    if event == 'pull_request' and not cifuzz.build_fuzzers(
            oss_fuzz_project_name, github_repo_name, workspace, pr_ref=pr_ref):
        logging.error(
            'Error building fuzzers for project %s with pull request %s.',
            oss_fuzz_project_name, pr_ref)
        return returncode
    out_dir = os.path.join(workspace, 'out')
    if cifuzz.check_fuzzer_build(out_dir):
        return 0
    return returncode
예제 #3
0
 def test_invalid_project_name(self):
     """Test building fuzzers with invalid project name."""
     with tempfile.TemporaryDirectory() as tmp_dir, self.assertRaises(
             ValueError):
         cifuzz.build_fuzzers(
             'not_a_valid_project',
             'oss-fuzz',
             tmp_dir,
             commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523')
예제 #4
0
def main():
    """Runs OSS-Fuzz project's fuzzers for CI tools.
  This script is used to kick off the Github Actions CI tool. It is the
  entrypoint  of the Dockerfile in this directory. This action can be added to
  any OSS-Fuzz project's workflow that uses Github.

  Required environment variables:
    PROJECT_NAME: The name of OSS-Fuzz project.
    FUZZ_TIME: The length of time in seconds that fuzzers are to be run.
    GITHUB_REPOSITORY: The name of the Github repo that called this script.
    GITHUB_SHA: The commit SHA that triggered this script.
    GITHUB_REF: The pull request reference that triggered this script.
    GITHUB_EVENT_NAME: The name of the hook event that triggered this script.

  Returns:
    0 on success or 1 on Failure.
  """
    oss_fuzz_project_name = os.environ.get('PROJECT_NAME')
    fuzz_seconds = int(os.environ.get('FUZZ_SECONDS', 360))
    github_repo_name = os.path.basename(os.environ.get('GITHUB_REPOSITORY'))
    pr_ref = os.environ.get('GITHUB_REF')
    commit_sha = os.environ.get('GITHUB_SHA')
    event = os.environ.get('GITHUB_EVENT_NAME')

    # Get the shared volume directory and create required directorys.
    workspace = os.environ.get('GITHUB_WORKSPACE')
    if not workspace:
        logging.error(
            'This script needs to be run in the Github action context.')
        return 1

    if event == 'push' and not cifuzz.build_fuzzers(oss_fuzz_project_name,
                                                    github_repo_name,
                                                    workspace,
                                                    commit_sha=commit_sha):
        logging.error('Error building fuzzers for project %s with commit %s.',
                      oss_fuzz_project_name, commit_sha)
        return 1
    if event == 'pull_request' and not cifuzz.build_fuzzers(
            oss_fuzz_project_name, github_repo_name, workspace, pr_ref=pr_ref):
        logging.error(
            'Error building fuzzers for project %s with pull request %s.',
            oss_fuzz_project_name, pr_ref)
        return 1

    # Run the specified project's fuzzers from the build.
    run_status, bug_found = cifuzz.run_fuzzers(oss_fuzz_project_name,
                                               fuzz_seconds, workspace)
    if not run_status:
        logging.error('Error occured while running fuzzers for project %s.',
                      oss_fuzz_project_name)
        return 1
    if bug_found:
        logging.info('Bug found.')
        # Return 2 when a bug was found by a fuzzer causing the CI to fail.
        return 2
    return 0
예제 #5
0
 def test_invalid_commit_sha(self):
     """Tests building fuzzers with invalid commit SHA."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         config = create_config(project_name=EXAMPLE_PROJECT,
                                project_repo_name='oss-fuzz',
                                workspace=tmp_dir,
                                commit_sha='',
                                is_github=True)
         with self.assertRaises(AssertionError):
             cifuzz.build_fuzzers(config)
예제 #6
0
 def test_invalid_workspace(self):
     """Tests building fuzzers with invalid workspace."""
     config = create_config(
         project_name=EXAMPLE_PROJECT,
         project_repo_name='oss-fuzz',
         workspace='not/a/dir',
         commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523')
     self.assertFalse(cifuzz.build_fuzzers(config))
예제 #7
0
 def test_invalid_repo_name(self):
     """Tests building fuzzers with invalid repo name."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         config = create_config(
             project_name=EXAMPLE_PROJECT,
             project_repo_name='not-real-repo',
             workspace=tmp_dir,
             commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523')
         self.assertFalse(cifuzz.build_fuzzers(config))
예제 #8
0
def test_invalid_out(self):
  """Test building fuzzers with invalid out directory."""
  with tempfile.TemporaryDirectory() as tmp_dir:
    workspace_path = os.path.join(tmp_dir, 'workspace')
    os.mkdir(workspace_path)
    self.assertFalse(
        cifuzz.build_fuzzers(EXAMPLE_PROJECT, 'oss-fuzz',
                             '0b95fe1039ed7c38fea1f97078316bfc1030c523',
                             workspace_path, 'not/a/dir'))
예제 #9
0
 def test_invalid_repo_name(self):
     """Tests building fuzzers with invalid repo name."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         self.assertFalse(
             cifuzz.build_fuzzers(
                 EXAMPLE_PROJECT,
                 'not-real-repo',
                 tmp_dir,
                 commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523'))
예제 #10
0
 def test_invalid_workspace(self):
     """Tests building fuzzers with invalid workspace."""
     self.assertFalse(
         cifuzz.build_fuzzers(
             EXAMPLE_PROJECT,
             'oss-fuzz',
             'not/a/dir',
             commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523',
         ))
예제 #11
0
 def test_valid_project_curl_undefined(self):
     """Test that UBSAN can be detected from project.yaml"""
     with tempfile.TemporaryDirectory() as tmp_dir:
         self.assertTrue(
             cifuzz.build_fuzzers('curl',
                                  'curl',
                                  tmp_dir,
                                  pr_ref='fake_pr',
                                  sanitizer='undefined'))
예제 #12
0
 def test_invalid_pull_request(self):
     """Tests building fuzzers with invalid pull request."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         out_path = os.path.join(tmp_dir, 'out')
         os.mkdir(out_path)
         self.assertTrue(
             cifuzz.build_fuzzers(EXAMPLE_PROJECT,
                                  'oss-fuzz',
                                  tmp_dir,
                                  pr_ref='ref-1/merge'))
예제 #13
0
def test_invalid_commit_sha(self):
  """Test building fuzzers with invalid commit SHA."""
  with tempfile.TemporaryDirectory() as tmp_dir:
    out_path = os.path.join(tmp_dir, 'out')
    workspace_path = os.path.join(tmp_dir, 'workspace')
    os.mkdir(out_path)
    os.mkdir(workspace_path)
    self.assertFalse(
        cifuzz.build_fuzzers(EXAMPLE_PROJECT, 'oss-fuzz', '', workspace_path,
                             out_path))
예제 #14
0
def test_invalid_repo_name(self):
  """Test building fuzzers with invalid repo name."""
  with tempfile.TemporaryDirectory() as tmp_dir:
    out_path = os.path.join(tmp_dir, 'out')
    workspace_path = os.path.join(tmp_dir, 'workspace')
    os.mkdir(out_path)
    os.mkdir(workspace_path)
    self.assertFalse(
        cifuzz.build_fuzzers(EXAMPLE_PROJECT, 'not-real-repo',
                             '0b95fe1039ed7c38fea1f97078316bfc1030c523',
                             workspace_path, out_path))
예제 #15
0
def test_invalid_project_name(self):
  """Test building fuzzers with invalid project name."""
  with tempfile.TemporaryDirectory() as tmp_dir:
    out_path = os.path.join(tmp_dir, 'out')
    workspace_path = os.path.join(tmp_dir, 'workspace')
    os.mkdir(out_path)
    os.mkdir(workspace_path)
    self.assertFalse(
        cifuzz.build_fuzzers('not_a_valid_project', 'oss-fuzz',
                             '0b95fe1039ed7c38fea1f97078316bfc1030c523',
                             workspace_path, out_path))
예제 #16
0
 def test_valid_pull_request(self):
   """Test building fuzzers with valid pull request."""
   with tempfile.TemporaryDirectory() as tmp_dir:
     out_path = os.path.join(tmp_dir, 'out')
     os.mkdir(out_path)
     self.assertTrue(
         cifuzz.build_fuzzers(EXAMPLE_PROJECT,
                              'oss-fuzz',
                              tmp_dir,
                              pr_ref='refs/pull/1757/merge'))
     self.assertTrue(os.path.exists(os.path.join(out_path, 'do_stuff_fuzzer')))
예제 #17
0
  def test_cifuzz_env_var(self, mocked_docker_run, _, __, ___):
    """Tests that the CIFUZZ env var is set."""

    with tempfile.TemporaryDirectory() as tmp_dir:
      cifuzz.build_fuzzers(EXAMPLE_PROJECT,
                           EXAMPLE_PROJECT,
                           tmp_dir,
                           pr_ref='refs/pull/1757/merge')
    docker_run_command = mocked_docker_run.call_args_list[0][0][0]

    def command_has_env_var_arg(command, env_var_arg):
      for idx, element in enumerate(command):
        if idx == 0:
          continue

        if element == env_var_arg and command[idx - 1] == '-e':
          return True
      return False

    self.assertTrue(command_has_env_var_arg(docker_run_command, 'CIFUZZ=True'))
예제 #18
0
 def test_invalid_pull_request(self):
     """Tests building fuzzers with invalid pull request."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         out_path = os.path.join(tmp_dir, 'out')
         os.mkdir(out_path)
         config = create_config(project_name=EXAMPLE_PROJECT,
                                project_repo_name='oss-fuzz',
                                workspace=tmp_dir,
                                pr_ref='ref-1/merge',
                                base_ref='master',
                                is_github=True)
         self.assertTrue(cifuzz.build_fuzzers(config))
예제 #19
0
 def test_valid_commit(self):
   """Test building fuzzers with valid inputs."""
   with tempfile.TemporaryDirectory() as tmp_dir:
     out_path = os.path.join(tmp_dir, 'out')
     os.mkdir(out_path)
     self.assertTrue(
         cifuzz.build_fuzzers(
             EXAMPLE_PROJECT,
             'oss-fuzz',
             tmp_dir,
             commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523'))
     self.assertTrue(os.path.exists(os.path.join(out_path, EXAMPLE_FUZZER)))
예제 #20
0
 def test_valid(self):
   """Test building fuzzers with valid inputs."""
   with tempfile.TemporaryDirectory() as tmp_dir:
     out_path = os.path.join(tmp_dir, 'out')
     workspace_path = os.path.join(tmp_dir, 'workspace')
     os.mkdir(out_path)
     os.mkdir(workspace_path)
     self.assertTrue(
         cifuzz.build_fuzzers(EXAMPLE_PROJECT, 'oss-fuzz',
                              '0b95fe1039ed7c38fea1f97078316bfc1030c523',
                              workspace_path, out_path))
     self.assertTrue(os.path.exists(os.path.join(out_path, 'do_stuff_fuzzer')))
예제 #21
0
def main():
  """Build OSS-Fuzz project's fuzzers for CI tools.
  This script is used to kick off the Github Actions CI tool. It is the
  entrypoint of the Dockerfile in this directory. This action can be added to
  any OSS-Fuzz project's workflow that uses Github.

  Note: The resulting clusterfuzz binaries of this build are placed in
  the directory: ${GITHUB_WORKSPACE}/out

  Required environment variables:
    OSS_FUZZ_PROJECT_NAME: The name of OSS-Fuzz project.
    GITHUB_REPOSITORY: The name of the Github repo that called this script.
    GITHUB_SHA: The commit SHA that triggered this script.
    GITHUB_EVENT_NAME: The name of the hook event that triggered this script.
    GITHUB_EVENT_PATH:
      The path to the file containing the POST payload of the webhook:
      https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners
    GITHUB_WORKSPACE: The shared volume directory where input artifacts are.
    DRY_RUN: If true, no failures will surface.
    SANITIZER: The sanitizer to use when running fuzzers.

  Returns:
    0 on success or 1 on failure.
  """
  config = config_utils.BuildFuzzersConfig()

  if config.dry_run:
    # Sets the default return code on error to success.
    returncode = 0
  else:
    # The default return code when an error occurs.
    returncode = 1

  if not config.workspace:
    logging.error('This script needs to be run within Github actions.')
    return returncode

  if not cifuzz.build_fuzzers(config):
    logging.error(
        'Error building fuzzers for project %s (commit: %s, pr_ref: %s).',
        config.project_name, config.commit_sha, config.pr_ref)
    return returncode

  out_dir = os.path.join(config.workspace, 'out')
  if cifuzz.check_fuzzer_build(out_dir,
                               sanitizer=config.sanitizer,
                               allowed_broken_targets_percentage=config.
                               allowed_broken_targets_percentage):
    returncode = 0

  return returncode
예제 #22
0
 def test_valid_pull_request(self):
     """Tests building fuzzers with valid pull request."""
     with tempfile.TemporaryDirectory() as tmp_dir:
         out_path = os.path.join(tmp_dir, 'out')
         os.mkdir(out_path)
         # TODO(metzman): What happens when this branch closes?
         config = create_config(project_name=EXAMPLE_PROJECT,
                                project_repo_name='oss-fuzz',
                                workspace=tmp_dir,
                                pr_ref='refs/pull/1757/merge',
                                base_ref='master',
                                is_github=True)
         self.assertTrue(cifuzz.build_fuzzers(config))
         self.assertTrue(
             os.path.exists(os.path.join(out_path, EXAMPLE_BUILD_FUZZER)))
예제 #23
0
 def test_valid(self):
   """Test run_fuzzers with a valid build."""
   with tempfile.TemporaryDirectory() as tmp_dir:
     out_path = os.path.join(tmp_dir, 'out')
     os.mkdir(out_path)
     self.assertTrue(
         cifuzz.build_fuzzers(
             EXAMPLE_PROJECT,
             'oss-fuzz',
             tmp_dir,
             commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523'))
     self.assertTrue(os.path.exists(os.path.join(out_path, 'do_stuff_fuzzer')))
     run_success, bug_found = cifuzz.run_fuzzers(5, tmp_dir)
   self.assertTrue(run_success)
   self.assertTrue(bug_found)
예제 #24
0
    def test_valid_commit(self):
        """Tests building fuzzers with valid inputs."""
        with tempfile.TemporaryDirectory() as tmp_dir:
            out_path = os.path.join(tmp_dir, 'out')
            os.mkdir(out_path)
            config = create_config(
                project_name=EXAMPLE_PROJECT,
                project_repo_name='oss-fuzz',
                workspace=tmp_dir,
                commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523',
                base_commit='da0746452433dc18bae699e355a9821285d863c8',
                is_github=True)
            self.assertTrue(cifuzz.build_fuzzers(config))

            self.assertTrue(
                os.path.exists(os.path.join(out_path, EXAMPLE_BUILD_FUZZER)))
예제 #25
0
 def test_external_project(self):
   """Tests building fuzzers from an external project."""
   project_name = 'external-project'
   project_src_path = os.path.join(TEST_FILES_PATH, project_name)
   build_integration_path = os.path.join(project_src_path, 'oss-fuzz')
   with tempfile.TemporaryDirectory() as tmp_dir:
     out_path = os.path.join(tmp_dir, 'out')
     os.mkdir(out_path)
     self.assertTrue(
         cifuzz.build_fuzzers(project_name,
                              project_name,
                              tmp_dir,
                              project_src_path=project_src_path,
                              build_integration_path=build_integration_path))
     self.assertTrue(
         os.path.exists(os.path.join(out_path, EXAMPLE_BUILD_FUZZER)))
예제 #26
0
 def test_reproduce_false(self):
   """Checks CIFuzz doesn't report an error when a crash isn't reproducible."""
   with tempfile.TemporaryDirectory() as tmp_dir:
     out_path = os.path.join(tmp_dir, 'out')
     os.mkdir(out_path)
     self.assertTrue(
         cifuzz.build_fuzzers(
             EXAMPLE_PROJECT,
             'oss-fuzz',
             tmp_dir,
             commit_sha='0b95fe1039ed7c38fea1f97078316bfc1030c523'))
     with unittest.mock.patch.object(fuzz_target.FuzzTarget,
                                     'is_reproducible',
                                     return_value=False):
       run_success, bug_found = cifuzz.run_fuzzers(5, tmp_dir)
       self.assertTrue(run_success)
       self.assertFalse(bug_found)
예제 #27
0
 def test_external_github_project(self):
     """Tests building fuzzers from an external project on Github."""
     project_name = 'external-project'
     build_integration_path = 'fuzzer-build-integration'
     git_url = 'https://github.com/jonathanmetzman/cifuzz-external-example.git'
     with tempfile.TemporaryDirectory() as tmp_dir:
         out_path = os.path.join(tmp_dir, 'out')
         os.mkdir(out_path)
         # This test is dependant on the state of
         # github.com/jonathanmetzman/cifuzz-external-example.
         config = create_config(
             project_name=project_name,
             project_repo_name=project_name,
             workspace=tmp_dir,
             build_integration_path=build_integration_path,
             git_url=git_url,
             commit_sha='HEAD',
             base_commit='HEAD^1')
         self.assertTrue(cifuzz.build_fuzzers(config))
         self.assertTrue(
             os.path.exists(os.path.join(out_path, EXAMPLE_BUILD_FUZZER)))
예제 #28
0
 def test_valid_project_curl(self, sanitizer):
     """Tests that MSAN can be detected from project.yaml"""
     with tempfile.TemporaryDirectory() as tmp_dir:
         self.assertTrue(
             cifuzz.build_fuzzers(self._create_config(tmp_dir, sanitizer)))
def main():
    """Build OSS-Fuzz project's fuzzers for CI tools.
  This script is used to kick off the Github Actions CI tool. It is the
  entrypoint of the Dockerfile in this directory. This action can be added to
  any OSS-Fuzz project's workflow that uses Github.

  Note: The resulting clusterfuzz binaries of this build are placed in
  the directory: ${GITHUB_WORKSPACE}/out

  Required environment variables:
    OSS_FUZZ_PROJECT_NAME: The name of OSS-Fuzz project.
    GITHUB_REPOSITORY: The name of the Github repo that called this script.
    GITHUB_SHA: The commit SHA that triggered this script.
    GITHUB_EVENT_NAME: The name of the hook event that triggered this script.
    GITHUB_EVENT_PATH:
      The path to the file containing the POST payload of the webhook:
      https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners
    GITHUB_WORKSPACE: The shared volume directory where input artifacts are.
    DRY_RUN: If true, no failures will surface.
    SANITIZER: The sanitizer to use when running fuzzers.

  Returns:
    0 on success or 1 on Failure.
  """
    oss_fuzz_project_name = os.environ.get('OSS_FUZZ_PROJECT_NAME')
    github_repo_name = os.path.basename(os.environ.get('GITHUB_REPOSITORY'))
    commit_sha = os.environ.get('GITHUB_SHA')
    event = os.environ.get('GITHUB_EVENT_NAME')
    workspace = os.environ.get('GITHUB_WORKSPACE')
    sanitizer = os.environ.get('SANITIZER').lower()

    # Check if failures should not be reported.
    dry_run = (os.environ.get('DRY_RUN').lower() == 'true')

    # The default return code when an error occurs.
    returncode = 1
    if dry_run:
        # Sets the default return code on error to success.
        returncode = 0

    if not workspace:
        logging.error(
            'This script needs to be run in the Github action context.')
        return returncode

    if event == 'push' and not cifuzz.build_fuzzers(oss_fuzz_project_name,
                                                    github_repo_name,
                                                    workspace,
                                                    commit_sha=commit_sha,
                                                    sanitizer=sanitizer):
        logging.error('Error building fuzzers for project %s with commit %s.',
                      oss_fuzz_project_name, commit_sha)
        return returncode

    if event == 'pull_request':
        with open(os.environ.get('GITHUB_EVENT_PATH'),
                  encoding='utf-8') as file:
            event = json.load(file)
            pr_ref = 'refs/pull/{0}/merge'.format(
                event['pull_request']['number'])
            if not cifuzz.build_fuzzers(oss_fuzz_project_name,
                                        github_repo_name,
                                        workspace,
                                        pr_ref=pr_ref,
                                        sanitizer=sanitizer):
                logging.error(
                    'Error building fuzzers for project %s with pull request %s.',
                    oss_fuzz_project_name, pr_ref)
                return returncode

    out_dir = os.path.join(workspace, 'out')
    if cifuzz.check_fuzzer_build(out_dir, sanitizer=sanitizer):
        return 0
    return returncode
예제 #30
0
def main():
    """Build OSS-Fuzz project's fuzzers for CI tools.
  This script is used to kick off the Github Actions CI tool. It is the
  entrypoint of the Dockerfile in this directory. This action can be added to
  any OSS-Fuzz project's workflow that uses Github.

  Note: The resulting clusterfuzz binaries of this build are placed in
  the directory: ${GITHUB_WORKSPACE}/out

  Required environment variables:
    OSS_FUZZ_PROJECT_NAME: The name of OSS-Fuzz project.
    GITHUB_REPOSITORY: The name of the Github repo that called this script.
    GITHUB_SHA: The commit SHA that triggered this script.
    GITHUB_EVENT_NAME: The name of the hook event that triggered this script.
    GITHUB_EVENT_PATH:
      The path to the file containing the POST payload of the webhook:
      https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners
    GITHUB_WORKSPACE: The shared volume directory where input artifacts are.
    DRY_RUN: If true, no failures will surface.
    SANITIZER: The sanitizer to use when running fuzzers.

  Returns:
    0 on success or 1 on failure.
  """
    oss_fuzz_project_name = os.getenv('OSS_FUZZ_PROJECT_NAME')
    github_repo_name = os.path.basename(os.getenv('GITHUB_REPOSITORY'))
    commit_sha = os.getenv('GITHUB_SHA')
    event = os.getenv('GITHUB_EVENT_NAME')
    workspace = os.getenv('GITHUB_WORKSPACE')
    sanitizer = os.getenv('SANITIZER').lower()
    project_src_path = get_project_src_path(workspace)
    build_integration_path = os.getenv('BUILD_INTEGRATION_PATH')
    allowed_broken_targets_percentage = os.getenv(
        'ALLOWED_BROKEN_TARGETS_PERCENTAGE')

    # Check if failures should not be reported.
    dry_run = os.getenv('DRY_RUN').lower() == 'true'
    if dry_run:
        # Sets the default return code on error to success.
        returncode = 0
    else:
        # The default return code when an error occurs.
        returncode = 1

    if not workspace:
        logging.error('This script needs to be run within Github actions.')
        return returncode

    if event == 'pull_request':
        event_path = os.getenv('GITHUB_EVENT_PATH')
        pr_ref = get_pr_ref(event_path)
    else:
        pr_ref = None

    if not cifuzz.build_fuzzers(oss_fuzz_project_name,
                                github_repo_name,
                                workspace,
                                commit_sha=commit_sha,
                                pr_ref=pr_ref,
                                sanitizer=sanitizer,
                                project_src_path=project_src_path,
                                build_integration_path=build_integration_path):
        logging.error(
            'Error building fuzzers for project %s (commit: %s, pr_ref: %s).',
            oss_fuzz_project_name, commit_sha, pr_ref)
        return returncode

    out_dir = os.path.join(workspace, 'out')
    if cifuzz.check_fuzzer_build(
            out_dir,
            sanitizer=sanitizer,
            allowed_broken_targets_percentage=allowed_broken_targets_percentage
    ):
        returncode = 0

    return returncode