def run_fuzzers_entrypoint():
    """This is the entrypoint for the run_fuzzers github action.
  This action can be added to any OSS-Fuzz project's workflow that uses
  Github."""
    config = config_utils.RunFuzzersConfig()
    # The default return code when an error occurs.
    returncode = 1
    if config.dry_run:
        # Sets the default return code on error to success.
        returncode = 0

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

    delete_unneeded_docker_images(config)
    # Run the specified project's fuzzers from the build.
    result = run_fuzzers.run_fuzzers(config)
    if result == run_fuzzers.RunFuzzersResult.ERROR:
        logging.error('Error occurred while running in workspace %s.',
                      config.workspace)
        return returncode
    if result == run_fuzzers.RunFuzzersResult.BUG_FOUND:
        logging.info('Bug found.')
        if not config.dry_run:
            # Return 2 when a bug was found by a fuzzer causing the CI to fail.
            return 2
    return 0
示例#2
0
def _create_config(**kwargs):
    """Creates a config object and then sets every attribute that is a key in
  |kwargs| to the corresponding value. Asserts that each key in |kwargs| is an
  attribute of Config."""
    with mock.patch('os.path.basename', return_value=None), mock.patch(
            'config_utils.get_project_src_path',
            return_value=None), mock.patch('config_utils._is_dry_run',
                                           return_value=True):
        config = config_utils.RunFuzzersConfig()

    for key, value in kwargs.items():
        assert hasattr(config, key), 'Config doesn\'t have attribute: ' + key
        setattr(config, key, value)
    return config
示例#3
0
def main():
    """Runs OSS-Fuzz project's fuzzers for CI tools.
  This is the entrypoint for the run_fuzzers github action.
  This action can be added to any OSS-Fuzz project's workflow that uses Github.

  NOTE: libFuzzer binaries must be located in the ${GITHUB_WORKSPACE}/out
  directory in order for this action to be used. This action will only fuzz the
  binaries that are located in that directory. It is recommended that you add
  the build_fuzzers action preceding this one.

  NOTE: Any crash report will be in the filepath:
  ${GITHUB_WORKSPACE}/out/testcase
  This can be used in parallel with the upload-artifact action to surface the
  logs.

  Required environment variables:
    FUZZ_SECONDS: The length of time in seconds that fuzzers are to be run.
    GITHUB_WORKSPACE: The shared volume directory where input artifacts are.
    DRY_RUN: If true, no failures will surface.
    OSS_FUZZ_PROJECT_NAME: The name of the relevant OSS-Fuzz project.
    SANITIZER: The sanitizer to use when running fuzzers.

  Returns:
    0 on success or 1 on failure.
  """
    config = config_utils.RunFuzzersConfig()
    # The default return code when an error occurs.
    returncode = 1
    if config.dry_run:
        # Sets the default return code on error to success.
        returncode = 0

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

    delete_unneeded_docker_images(config)
    # Run the specified project's fuzzers from the build.
    result = run_fuzzers.run_fuzzers(config)
    if result == run_fuzzers.RunFuzzersResult.ERROR:
        logging.error('Error occurred while running in workspace %s.',
                      config.workspace)
        return returncode
    if result == run_fuzzers.RunFuzzersResult.BUG_FOUND:
        logging.info('Bug found.')
        if not config.dry_run:
            # Return 2 when a bug was found by a fuzzer causing the CI to fail.
            return 2
    return 0
示例#4
0
def _create_config(**kwargs):
  """Creates a config object and then sets every attribute that is a key in
  |kwargs| to the corresponding value. Asserts that each key in |kwargs| is an
  attribute of Config."""
  defaults = {'is_github': True, 'project_name': EXAMPLE_PROJECT}
  for default_key, default_value in defaults.items():
    if default_key not in kwargs:
      kwargs[default_key] = default_value

  with mock.patch('os.path.basename', return_value=None), mock.patch(
      'config_utils.get_project_src_path',
      return_value=None), mock.patch('config_utils._is_dry_run',
                                     return_value=True):
    config = config_utils.RunFuzzersConfig()

  for key, value in kwargs.items():
    assert hasattr(config, key), 'Config doesn\'t have attribute: ' + key
    setattr(config, key, value)
  return config
示例#5
0
 def _create_config(self):
     return config_utils.RunFuzzersConfig()
示例#6
0
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests the functionality of the docker module."""
import unittest
from unittest import mock

import config_utils
import docker

CONTAINER_NAME = 'example-container'
config = config_utils.RunFuzzersConfig()
config.workspace = '/workspace'
WORKSPACE = config_utils.Workspace(config)
SANITIZER = 'example-sanitizer'
LANGUAGE = 'example-language'


class GetProjectImageTest(unittest.TestCase):
    """Tests for get_project_image."""
    def test_get_project_image(self):
        """Tests that get_project_image_name works as intended."""
        project = 'my-project'
        self.assertEqual(docker.get_project_image_name(project),
                         'gcr.io/oss-fuzz/my-project')