Add files using upload-large-folder tool
Browse files- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/bisect_clang_test.py +294 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile +420 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_centipede +32 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_fuzztests.sh +126 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_honggfuzz +33 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_javascript_fuzzer +37 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_libfuzzer +25 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/debug_afl +40 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_deps.sh +44 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_java.sh +31 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_python.sh +23 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_ruby.sh +25 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_rust.sh +22 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/ossfuzz_coverage_runner.go +69 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/precompile_centipede +49 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/srcmap +66 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/Dockerfile +139 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/bad_build_check +494 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/coverage_helper +17 -0
- local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/install_javascript.sh +30 -0
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/bisect_clang_test.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019 Google Inc.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
#
|
| 15 |
+
################################################################################
|
| 16 |
+
"""Tests for bisect_clang.py"""
|
| 17 |
+
import os
|
| 18 |
+
from unittest import mock
|
| 19 |
+
import unittest
|
| 20 |
+
|
| 21 |
+
import bisect_clang
|
| 22 |
+
|
| 23 |
+
FILE_DIRECTORY = os.path.dirname(__file__)
|
| 24 |
+
LLVM_REPO_PATH = '/llvm-project'
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_git_command(*args):
|
| 28 |
+
"""Returns a git command for the LLVM repo with |args| as arguments."""
|
| 29 |
+
return ['git', '-C', LLVM_REPO_PATH] + list(args)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def patch_environ(testcase_obj):
|
| 33 |
+
"""Patch environment."""
|
| 34 |
+
env = {}
|
| 35 |
+
patcher = mock.patch.dict(os.environ, env)
|
| 36 |
+
testcase_obj.addCleanup(patcher.stop)
|
| 37 |
+
patcher.start()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class BisectClangTestMixin: # pylint: disable=too-few-public-methods
|
| 41 |
+
"""Useful mixin for bisect_clang unittests."""
|
| 42 |
+
|
| 43 |
+
def setUp(self): # pylint: disable=invalid-name
|
| 44 |
+
"""Initialization method for unittests."""
|
| 45 |
+
patch_environ(self)
|
| 46 |
+
os.environ['SRC'] = '/src'
|
| 47 |
+
os.environ['WORK'] = '/work'
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class GetClangBuildEnvTest(BisectClangTestMixin, unittest.TestCase):
|
| 51 |
+
"""Tests for get_clang_build_env."""
|
| 52 |
+
|
| 53 |
+
def test_cflags(self):
|
| 54 |
+
"""Test that CFLAGS are not used compiling clang."""
|
| 55 |
+
os.environ['CFLAGS'] = 'blah'
|
| 56 |
+
self.assertNotIn('CFLAGS', bisect_clang.get_clang_build_env())
|
| 57 |
+
|
| 58 |
+
def test_cxxflags(self):
|
| 59 |
+
"""Test that CXXFLAGS are not used compiling clang."""
|
| 60 |
+
os.environ['CXXFLAGS'] = 'blah'
|
| 61 |
+
self.assertNotIn('CXXFLAGS', bisect_clang.get_clang_build_env())
|
| 62 |
+
|
| 63 |
+
def test_other_variables(self):
|
| 64 |
+
"""Test that other env vars are used when compiling clang."""
|
| 65 |
+
key = 'other'
|
| 66 |
+
value = 'blah'
|
| 67 |
+
os.environ[key] = value
|
| 68 |
+
self.assertEqual(value, bisect_clang.get_clang_build_env()[key])
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def read_test_data(filename):
|
| 72 |
+
"""Returns data from |filename| in the test_data directory."""
|
| 73 |
+
with open(os.path.join(FILE_DIRECTORY, 'test_data', filename)) as file_handle:
|
| 74 |
+
return file_handle.read()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class SearchBisectOutputTest(BisectClangTestMixin, unittest.TestCase):
|
| 78 |
+
"""Tests for search_bisect_output."""
|
| 79 |
+
|
| 80 |
+
def test_search_bisect_output(self):
|
| 81 |
+
"""Test that search_bisect_output finds the responsible commit when one
|
| 82 |
+
exists."""
|
| 83 |
+
test_data = read_test_data('culprit-commit.txt')
|
| 84 |
+
self.assertEqual('ac9ee01fcbfac745aaedca0393a8e1c8a33acd8d',
|
| 85 |
+
bisect_clang.search_bisect_output(test_data))
|
| 86 |
+
|
| 87 |
+
def test_search_bisect_output_none(self):
|
| 88 |
+
"""Test that search_bisect_output doesnt find a non-existent culprit
|
| 89 |
+
commit."""
|
| 90 |
+
self.assertIsNone(bisect_clang.search_bisect_output('hello'))
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def create_mock_popen(
|
| 94 |
+
output=bytes('', 'utf-8'), err=bytes('', 'utf-8'), returncode=0):
|
| 95 |
+
"""Creates a mock subprocess.Popen."""
|
| 96 |
+
|
| 97 |
+
class MockPopen:
|
| 98 |
+
"""Mock subprocess.Popen."""
|
| 99 |
+
commands = []
|
| 100 |
+
testcases_written = []
|
| 101 |
+
|
| 102 |
+
def __init__(self, command, *args, **kwargs): # pylint: disable=unused-argument
|
| 103 |
+
"""Inits the MockPopen."""
|
| 104 |
+
stdout = kwargs.pop('stdout', None)
|
| 105 |
+
self.command = command
|
| 106 |
+
self.commands.append(command)
|
| 107 |
+
self.stdout = None
|
| 108 |
+
self.stderr = None
|
| 109 |
+
self.returncode = returncode
|
| 110 |
+
if hasattr(stdout, 'write'):
|
| 111 |
+
self.stdout = stdout
|
| 112 |
+
|
| 113 |
+
def communicate(self, input_data=None): # pylint: disable=unused-argument
|
| 114 |
+
"""Mock subprocess.Popen.communicate."""
|
| 115 |
+
if self.stdout:
|
| 116 |
+
self.stdout.write(output)
|
| 117 |
+
|
| 118 |
+
if self.stderr:
|
| 119 |
+
self.stderr.write(err)
|
| 120 |
+
|
| 121 |
+
return output, err
|
| 122 |
+
|
| 123 |
+
def poll(self, input_data=None): # pylint: disable=unused-argument
|
| 124 |
+
"""Mock subprocess.Popen.poll."""
|
| 125 |
+
return self.returncode
|
| 126 |
+
|
| 127 |
+
return MockPopen
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def mock_prepare_build_impl(llvm_project_path): # pylint: disable=unused-argument
|
| 131 |
+
"""Mocked prepare_build function."""
|
| 132 |
+
return '/work/llvm-build'
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class BuildClangTest(BisectClangTestMixin, unittest.TestCase):
|
| 136 |
+
"""Tests for build_clang."""
|
| 137 |
+
|
| 138 |
+
def test_build_clang_test(self):
|
| 139 |
+
"""Tests that build_clang works as intended."""
|
| 140 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 141 |
+
with mock.patch('bisect_clang.prepare_build', mock_prepare_build_impl):
|
| 142 |
+
llvm_src_dir = '/src/llvm-project'
|
| 143 |
+
bisect_clang.build_clang(llvm_src_dir)
|
| 144 |
+
self.assertEqual([['ninja', '-C', '/work/llvm-build', 'install']],
|
| 145 |
+
mock_popen.commands)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class GitRepoTest(BisectClangTestMixin, unittest.TestCase):
|
| 149 |
+
"""Tests for GitRepo."""
|
| 150 |
+
|
| 151 |
+
# TODO(metzman): Mock filesystem. Until then, use a real directory.
|
| 152 |
+
|
| 153 |
+
def setUp(self):
|
| 154 |
+
super().setUp()
|
| 155 |
+
self.git = bisect_clang.GitRepo(LLVM_REPO_PATH)
|
| 156 |
+
self.good_commit = 'good_commit'
|
| 157 |
+
self.bad_commit = 'bad_commit'
|
| 158 |
+
self.test_command = 'testcommand'
|
| 159 |
+
|
| 160 |
+
def test_do_command(self):
|
| 161 |
+
"""Test do_command creates a new process as intended."""
|
| 162 |
+
# TODO(metzman): Test directory changing behavior.
|
| 163 |
+
command = ['subcommand', '--option']
|
| 164 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 165 |
+
self.git.do_command(command)
|
| 166 |
+
self.assertEqual([get_git_command('subcommand', '--option')],
|
| 167 |
+
mock_popen.commands)
|
| 168 |
+
|
| 169 |
+
def _test_test_start_commit_unexpected(self, label, commit, returncode):
|
| 170 |
+
"""Tests test_start_commit works as intended when the test returns an
|
| 171 |
+
unexpected value."""
|
| 172 |
+
|
| 173 |
+
def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
|
| 174 |
+
if command == self.test_command:
|
| 175 |
+
return returncode, '', ''
|
| 176 |
+
return 0, '', ''
|
| 177 |
+
|
| 178 |
+
with mock.patch('bisect_clang.execute', mock_execute_impl):
|
| 179 |
+
with mock.patch('bisect_clang.prepare_build', mock_prepare_build_impl):
|
| 180 |
+
with self.assertRaises(bisect_clang.BisectError):
|
| 181 |
+
self.git.test_start_commit(commit, label, self.test_command)
|
| 182 |
+
|
| 183 |
+
def test_test_start_commit_bad_zero(self):
|
| 184 |
+
"""Tests test_start_commit works as intended when the test on the first bad
|
| 185 |
+
commit returns 0."""
|
| 186 |
+
self._test_test_start_commit_unexpected('bad', self.bad_commit, 0)
|
| 187 |
+
|
| 188 |
+
def test_test_start_commit_good_nonzero(self):
|
| 189 |
+
"""Tests test_start_commit works as intended when the test on the first good
|
| 190 |
+
commit returns nonzero."""
|
| 191 |
+
self._test_test_start_commit_unexpected('good', self.good_commit, 1)
|
| 192 |
+
|
| 193 |
+
def test_test_start_commit_good_zero(self):
|
| 194 |
+
"""Tests test_start_commit works as intended when the test on the first good
|
| 195 |
+
commit returns 0."""
|
| 196 |
+
self._test_test_start_commit_expected('good', self.good_commit, 0) # pylint: disable=no-value-for-parameter
|
| 197 |
+
|
| 198 |
+
@mock.patch('bisect_clang.build_clang')
|
| 199 |
+
def _test_test_start_commit_expected(self, label, commit, returncode,
|
| 200 |
+
mock_build_clang):
|
| 201 |
+
"""Tests test_start_commit works as intended when the test returns an
|
| 202 |
+
expected value."""
|
| 203 |
+
command_args = []
|
| 204 |
+
|
| 205 |
+
def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
|
| 206 |
+
command_args.append(command)
|
| 207 |
+
if command == self.test_command:
|
| 208 |
+
return returncode, '', ''
|
| 209 |
+
return 0, '', ''
|
| 210 |
+
|
| 211 |
+
with mock.patch('bisect_clang.execute', mock_execute_impl):
|
| 212 |
+
self.git.test_start_commit(commit, label, self.test_command)
|
| 213 |
+
self.assertEqual([
|
| 214 |
+
get_git_command('checkout', commit), self.test_command,
|
| 215 |
+
get_git_command('bisect', label)
|
| 216 |
+
], command_args)
|
| 217 |
+
mock_build_clang.assert_called_once_with(LLVM_REPO_PATH)
|
| 218 |
+
|
| 219 |
+
def test_test_start_commit_bad_nonzero(self):
|
| 220 |
+
"""Tests test_start_commit works as intended when the test on the first bad
|
| 221 |
+
commit returns nonzero."""
|
| 222 |
+
self._test_test_start_commit_expected('bad', self.bad_commit, 1) # pylint: disable=no-value-for-parameter
|
| 223 |
+
|
| 224 |
+
@mock.patch('bisect_clang.GitRepo.test_start_commit')
|
| 225 |
+
def test_bisect_start(self, mock_test_start_commit):
|
| 226 |
+
"""Tests bisect_start works as intended."""
|
| 227 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 228 |
+
self.git.bisect_start(self.good_commit, self.bad_commit,
|
| 229 |
+
self.test_command)
|
| 230 |
+
self.assertEqual(get_git_command('bisect', 'start'),
|
| 231 |
+
mock_popen.commands[0])
|
| 232 |
+
mock_test_start_commit.assert_has_calls([
|
| 233 |
+
mock.call('bad_commit', 'bad', 'testcommand'),
|
| 234 |
+
mock.call('good_commit', 'good', 'testcommand')
|
| 235 |
+
])
|
| 236 |
+
|
| 237 |
+
def test_do_bisect_command(self):
|
| 238 |
+
"""Test do_bisect_command executes a git bisect subcommand as intended."""
|
| 239 |
+
subcommand = 'subcommand'
|
| 240 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 241 |
+
self.git.do_bisect_command(subcommand)
|
| 242 |
+
self.assertEqual([get_git_command('bisect', subcommand)],
|
| 243 |
+
mock_popen.commands)
|
| 244 |
+
|
| 245 |
+
@mock.patch('bisect_clang.build_clang')
|
| 246 |
+
def _test_test_commit(self, label, output, returncode, mock_build_clang):
|
| 247 |
+
"""Test test_commit works as intended."""
|
| 248 |
+
command_args = []
|
| 249 |
+
|
| 250 |
+
def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
|
| 251 |
+
command_args.append(command)
|
| 252 |
+
if command == self.test_command:
|
| 253 |
+
return returncode, output, ''
|
| 254 |
+
return 0, output, ''
|
| 255 |
+
|
| 256 |
+
with mock.patch('bisect_clang.execute', mock_execute_impl):
|
| 257 |
+
result = self.git.test_commit(self.test_command)
|
| 258 |
+
self.assertEqual([self.test_command,
|
| 259 |
+
get_git_command('bisect', label)], command_args)
|
| 260 |
+
mock_build_clang.assert_called_once_with(LLVM_REPO_PATH)
|
| 261 |
+
return result
|
| 262 |
+
|
| 263 |
+
def test_test_commit_good(self):
|
| 264 |
+
"""Test test_commit labels a good commit as good."""
|
| 265 |
+
self.assertIsNone(self._test_test_commit('good', '', 0)) # pylint: disable=no-value-for-parameter
|
| 266 |
+
|
| 267 |
+
def test_test_commit_bad(self):
|
| 268 |
+
"""Test test_commit labels a bad commit as bad."""
|
| 269 |
+
self.assertIsNone(self._test_test_commit('bad', '', 1)) # pylint: disable=no-value-for-parameter
|
| 270 |
+
|
| 271 |
+
def test_test_commit_culprit(self):
|
| 272 |
+
"""Test test_commit returns the culprit"""
|
| 273 |
+
test_data = read_test_data('culprit-commit.txt')
|
| 274 |
+
self.assertEqual('ac9ee01fcbfac745aaedca0393a8e1c8a33acd8d',
|
| 275 |
+
self._test_test_commit('good', test_data, 0)) # pylint: disable=no-value-for-parameter
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
class GetTargetArchToBuildTest(unittest.TestCase):
|
| 279 |
+
"""Tests for get_target_arch_to_build."""
|
| 280 |
+
|
| 281 |
+
def test_unrecognized(self):
|
| 282 |
+
"""Test that an unrecognized architecture raises an exception."""
|
| 283 |
+
with mock.patch('bisect_clang.execute') as mock_execute:
|
| 284 |
+
mock_execute.return_value = (None, 'mips', None)
|
| 285 |
+
with self.assertRaises(Exception):
|
| 286 |
+
bisect_clang.get_clang_target_arch()
|
| 287 |
+
|
| 288 |
+
def test_recognized(self):
|
| 289 |
+
"""Test that a recognized architecture returns the expected value."""
|
| 290 |
+
arch_pairs = {'x86_64': 'X86', 'aarch64': 'AArch64'}
|
| 291 |
+
for uname_result, clang_target in arch_pairs.items():
|
| 292 |
+
with mock.patch('bisect_clang.execute') as mock_execute:
|
| 293 |
+
mock_execute.return_value = (None, uname_result, None)
|
| 294 |
+
self.assertEqual(clang_target, bisect_clang.get_clang_target_arch())
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo "---------------------------------------------------------------"
|
| 19 |
+
|
| 20 |
+
sysctl -w vm.mmap_rnd_bits=28
|
| 21 |
+
|
| 22 |
+
OSS_FUZZ_ON_DEMAND="${OSS_FUZZ_ON_DEMAND:-0}"
|
| 23 |
+
|
| 24 |
+
# Used for Rust introspector builds
|
| 25 |
+
RUST_SANITIZER=$SANITIZER
|
| 26 |
+
|
| 27 |
+
if [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 28 |
+
if [ "$FUZZING_ENGINE" != "libfuzzer" ] && [ "$FUZZING_ENGINE" != "wycheproof" ]; then
|
| 29 |
+
echo "ERROR: JVM projects can be fuzzed with libFuzzer or tested with wycheproof engines only."
|
| 30 |
+
exit 1
|
| 31 |
+
fi
|
| 32 |
+
if [ "$SANITIZER" != "address" ] && [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "undefined" ] && [ "$SANITIZER" != "none" ] && [ "$SANITIZER" != "introspector" ]; then
|
| 33 |
+
echo "ERROR: JVM projects can be fuzzed with AddressSanitizer or UndefinedBehaviorSanitizer or Introspector only."
|
| 34 |
+
exit 1
|
| 35 |
+
fi
|
| 36 |
+
if [ "$ARCHITECTURE" != "x86_64" ]; then
|
| 37 |
+
echo "ERROR: JVM projects can be fuzzed on x86_64 architecture only."
|
| 38 |
+
exit 1
|
| 39 |
+
fi
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
if [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 43 |
+
if [ "$SANITIZER" = "introspector" ]; then
|
| 44 |
+
# introspector sanitizer flag will cause cargo build to fail. Rremove it
|
| 45 |
+
# temporarily, RUST_SANITIZER will hold the original sanitizer.
|
| 46 |
+
export SANITIZER=address
|
| 47 |
+
fi
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if [ "$FUZZING_LANGUAGE" = "javascript" ]; then
|
| 52 |
+
if [ "$FUZZING_ENGINE" != "libfuzzer" ]; then
|
| 53 |
+
echo "ERROR: JavaScript projects can be fuzzed with libFuzzer engine only."
|
| 54 |
+
exit 1
|
| 55 |
+
fi
|
| 56 |
+
if [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "none" ]; then
|
| 57 |
+
echo "ERROR: JavaScript projects cannot be fuzzed with sanitizers."
|
| 58 |
+
exit 1
|
| 59 |
+
fi
|
| 60 |
+
if [ "$ARCHITECTURE" != "x86_64" ]; then
|
| 61 |
+
echo "ERROR: JavaScript projects can be fuzzed on x86_64 architecture only."
|
| 62 |
+
exit 1
|
| 63 |
+
fi
|
| 64 |
+
fi
|
| 65 |
+
|
| 66 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 67 |
+
if [ "$FUZZING_ENGINE" != "libfuzzer" ]; then
|
| 68 |
+
echo "ERROR: Python projects can be fuzzed with libFuzzer engine only."
|
| 69 |
+
exit 1
|
| 70 |
+
fi
|
| 71 |
+
if [ "$SANITIZER" != "address" ] && [ "$SANITIZER" != "undefined" ] && [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "introspector" ]; then
|
| 72 |
+
echo "ERROR: Python projects can be fuzzed with AddressSanitizer or UndefinedBehaviorSanitizer or Coverage or Fuzz Introspector only."
|
| 73 |
+
exit 1
|
| 74 |
+
fi
|
| 75 |
+
if [ "$ARCHITECTURE" != "x86_64" ]; then
|
| 76 |
+
echo "ERROR: Python projects can be fuzzed on x86_64 architecture only."
|
| 77 |
+
exit 1
|
| 78 |
+
fi
|
| 79 |
+
fi
|
| 80 |
+
|
| 81 |
+
if [ -z "${SANITIZER_FLAGS-}" ]; then
|
| 82 |
+
FLAGS_VAR="SANITIZER_FLAGS_${SANITIZER}"
|
| 83 |
+
export SANITIZER_FLAGS=${!FLAGS_VAR-}
|
| 84 |
+
fi
|
| 85 |
+
|
| 86 |
+
if [[ $ARCHITECTURE == "i386" ]]; then
|
| 87 |
+
export CFLAGS="-m32 $CFLAGS"
|
| 88 |
+
cp -R /usr/i386/lib/* /usr/local/lib
|
| 89 |
+
cp -R /usr/i386/include/* /usr/local/include
|
| 90 |
+
fi
|
| 91 |
+
|
| 92 |
+
# Don't use a fuzzing engine with Jazzer which has libFuzzer built-in or with
|
| 93 |
+
# FuzzBench which will provide the fuzzing engine.
|
| 94 |
+
if [[ $FUZZING_ENGINE != "none" ]] && [[ $FUZZING_LANGUAGE != "jvm" ]] && [[ "${OSS_FUZZ_ON_DEMAND}" == "0" ]] ; then
|
| 95 |
+
# compile script might override environment, use . to call it.
|
| 96 |
+
. compile_${FUZZING_ENGINE}
|
| 97 |
+
fi
|
| 98 |
+
|
| 99 |
+
if [[ $SANITIZER_FLAGS = *sanitize=memory* ]]
|
| 100 |
+
then
|
| 101 |
+
# Take all libraries from lib/msan
|
| 102 |
+
# export CXXFLAGS_EXTRA="-L/usr/msan/lib $CXXFLAGS_EXTRA"
|
| 103 |
+
cp -R /usr/msan/lib/* /usr/local/lib/x86_64-unknown-linux-gnu/
|
| 104 |
+
cp -R /usr/msan/include/* /usr/local/include
|
| 105 |
+
|
| 106 |
+
echo 'Building without MSan instrumented libraries.'
|
| 107 |
+
fi
|
| 108 |
+
|
| 109 |
+
# Coverage flag overrides.
|
| 110 |
+
COVERAGE_FLAGS_VAR="COVERAGE_FLAGS_${SANITIZER}"
|
| 111 |
+
if [[ -n ${!COVERAGE_FLAGS_VAR+x} ]]
|
| 112 |
+
then
|
| 113 |
+
export COVERAGE_FLAGS="${!COVERAGE_FLAGS_VAR}"
|
| 114 |
+
fi
|
| 115 |
+
|
| 116 |
+
# Only need the default coverage instrumentation for libFuzzer or honggfuzz.
|
| 117 |
+
# Other engines bring their own.
|
| 118 |
+
if [ $FUZZING_ENGINE = "none" ] || [ $FUZZING_ENGINE = "afl" ] || [ $FUZZING_ENGINE = "centipede" ] || [ "${OSS_FUZZ_ON_DEMAND}" != "0" ]; then
|
| 119 |
+
export COVERAGE_FLAGS=
|
| 120 |
+
fi
|
| 121 |
+
|
| 122 |
+
# Rust does not support sanitizers and coverage flags via CFLAGS/CXXFLAGS, so
|
| 123 |
+
# use RUSTFLAGS.
|
| 124 |
+
# FIXME: Support code coverage once support is in.
|
| 125 |
+
# See https://github.com/rust-lang/rust/issues/34701.
|
| 126 |
+
if [ "$RUST_SANITIZER" == "introspector" ]; then
|
| 127 |
+
export RUSTFLAGS="-Cdebuginfo=2 -Cforce-frame-pointers"
|
| 128 |
+
elif [ "$SANITIZER" != "undefined" ] && [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "none" ] && [ "$ARCHITECTURE" != 'i386' ]; then
|
| 129 |
+
export RUSTFLAGS="--cfg fuzzing -Zsanitizer=${SANITIZER} -Cdebuginfo=1 -Cforce-frame-pointers"
|
| 130 |
+
else
|
| 131 |
+
export RUSTFLAGS="--cfg fuzzing -Cdebuginfo=1 -Cforce-frame-pointers"
|
| 132 |
+
fi
|
| 133 |
+
if [ "$SANITIZER" = "coverage" ]
|
| 134 |
+
then
|
| 135 |
+
# link to C++ from comment in f5098035eb1a14aa966c8651d88ea3d64323823d
|
| 136 |
+
export RUSTFLAGS="$RUSTFLAGS -Cinstrument-coverage -C link-arg=-lc++"
|
| 137 |
+
fi
|
| 138 |
+
|
| 139 |
+
# Add Rust libfuzzer flags.
|
| 140 |
+
# See https://github.com/rust-fuzz/libfuzzer/blob/master/build.rs#L12.
|
| 141 |
+
export CUSTOM_LIBFUZZER_PATH="$LIB_FUZZING_ENGINE_DEPRECATED"
|
| 142 |
+
export CUSTOM_LIBFUZZER_STD_CXX=c++
|
| 143 |
+
|
| 144 |
+
export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COVERAGE_FLAGS"
|
| 145 |
+
export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA"
|
| 146 |
+
|
| 147 |
+
if [ "$SANITIZER" = "undefined" ]; then
|
| 148 |
+
# Disable "function" sanitizer for C code for now, because many projects,
|
| 149 |
+
# possibly via legacy C code are affected.
|
| 150 |
+
# The projects should be fixed and this workaround be removed in the future.
|
| 151 |
+
# TODO(#11778):
|
| 152 |
+
# https://github.com/google/oss-fuzz/issues/11778
|
| 153 |
+
export CFLAGS="$CFLAGS -fno-sanitize=function"
|
| 154 |
+
fi
|
| 155 |
+
|
| 156 |
+
if [ "$FUZZING_LANGUAGE" = "go" ]; then
|
| 157 |
+
# required by Go 1.20
|
| 158 |
+
export CXX="${CXX} -lresolv"
|
| 159 |
+
fi
|
| 160 |
+
|
| 161 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 162 |
+
sanitizer_with_fuzzer_lib_dir=`python3 -c "import atheris; import os; print(atheris.path())"`
|
| 163 |
+
sanitizer_with_fuzzer_output_lib=$OUT/sanitizer_with_fuzzer.so
|
| 164 |
+
if [ "$SANITIZER" = "address" ]; then
|
| 165 |
+
cp $sanitizer_with_fuzzer_lib_dir/asan_with_fuzzer.so $sanitizer_with_fuzzer_output_lib
|
| 166 |
+
elif [ "$SANITIZER" = "undefined" ]; then
|
| 167 |
+
cp $sanitizer_with_fuzzer_lib_dir/ubsan_with_fuzzer.so $sanitizer_with_fuzzer_output_lib
|
| 168 |
+
fi
|
| 169 |
+
|
| 170 |
+
# Disable leak checking as it is unsupported.
|
| 171 |
+
export CFLAGS="$CFLAGS -fno-sanitize=function,leak,vptr,"
|
| 172 |
+
export CXXFLAGS="$CXXFLAGS -fno-sanitize=function,leak,vptr"
|
| 173 |
+
fi
|
| 174 |
+
|
| 175 |
+
# Copy latest llvm-symbolizer in $OUT for stack symbolization.
|
| 176 |
+
cp $(which llvm-symbolizer) $OUT/
|
| 177 |
+
|
| 178 |
+
# Copy Jazzer to $OUT if needed.
|
| 179 |
+
if [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 180 |
+
cp $(which jazzer_agent_deploy.jar) $(which jazzer_driver) $(which jazzer_junit.jar) $OUT/
|
| 181 |
+
jazzer_driver_with_sanitizer=$OUT/jazzer_driver_with_sanitizer
|
| 182 |
+
if [ "$SANITIZER" = "address" ]; then
|
| 183 |
+
cat > $jazzer_driver_with_sanitizer << 'EOF'
|
| 184 |
+
#!/bin/bash
|
| 185 |
+
this_dir=$(dirname "$0")
|
| 186 |
+
"$this_dir/jazzer_driver" --asan "$@"
|
| 187 |
+
EOF
|
| 188 |
+
elif [ "$SANITIZER" = "undefined" ]; then
|
| 189 |
+
cat > $jazzer_driver_with_sanitizer << 'EOF'
|
| 190 |
+
#!/bin/bash
|
| 191 |
+
this_dir=$(dirname "$0")
|
| 192 |
+
"$this_dir/jazzer_driver" --ubsan "$@"
|
| 193 |
+
EOF
|
| 194 |
+
elif [ "$SANITIZER" = "coverage" ] || [ "$SANITIZER" = "introspector" ]; then
|
| 195 |
+
# Coverage & introspector builds require no instrumentation.
|
| 196 |
+
cp $(which jazzer_driver) $jazzer_driver_with_sanitizer
|
| 197 |
+
fi
|
| 198 |
+
chmod +x $jazzer_driver_with_sanitizer
|
| 199 |
+
|
| 200 |
+
# Disable leak checking since the JVM triggers too many false positives.
|
| 201 |
+
export CFLAGS="$CFLAGS -fno-sanitize=leak"
|
| 202 |
+
export CXXFLAGS="$CXXFLAGS -fno-sanitize=leak"
|
| 203 |
+
fi
|
| 204 |
+
|
| 205 |
+
if [ "$SANITIZER" = "introspector" ] || [ "$RUST_SANITIZER" = "introspector" ]; then
|
| 206 |
+
export AR=llvm-ar
|
| 207 |
+
export NM=llvm-nm
|
| 208 |
+
export RANLIB=llvm-ranlib
|
| 209 |
+
|
| 210 |
+
export CFLAGS="$CFLAGS -g"
|
| 211 |
+
export CXXFLAGS="$CXXFLAGS -g"
|
| 212 |
+
export FI_BRANCH_PROFILE=1
|
| 213 |
+
export FUZZ_INTROSPECTOR=1
|
| 214 |
+
export FUZZ_INTROSPECTOR_AUTO_FUZZ=1
|
| 215 |
+
|
| 216 |
+
# Move ar and ranlib
|
| 217 |
+
mv /usr/bin/ar /usr/bin/old-ar
|
| 218 |
+
mv /usr/bin/nm /usr/bin/old-nm
|
| 219 |
+
mv /usr/bin/ranlib /usr/bin/old-ranlib
|
| 220 |
+
|
| 221 |
+
ln -sf /usr/local/bin/llvm-ar /usr/bin/ar
|
| 222 |
+
ln -sf /usr/local/bin/llvm-nm /usr/bin/nm
|
| 223 |
+
ln -sf /usr/local/bin/llvm-ranlib /usr/bin/ranlib
|
| 224 |
+
|
| 225 |
+
apt-get install -y libjpeg-dev zlib1g-dev libyaml-dev
|
| 226 |
+
python3 -m pip install --upgrade pip setuptools
|
| 227 |
+
python3 -m pip install cxxfilt pyyaml beautifulsoup4 lxml soupsieve rust-demangler
|
| 228 |
+
python3 -m pip install --prefer-binary matplotlib
|
| 229 |
+
|
| 230 |
+
# Install Fuzz-Introspector
|
| 231 |
+
pushd /fuzz-introspector/src
|
| 232 |
+
python3 -m pip install -e .
|
| 233 |
+
popd
|
| 234 |
+
|
| 235 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 236 |
+
python3 /fuzz-introspector/src/main.py light --language=python
|
| 237 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 238 |
+
elif [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 239 |
+
python3 /fuzz-introspector/src/main.py light --language=jvm
|
| 240 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 241 |
+
elif [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 242 |
+
python3 /fuzz-introspector/src/main.py light --language=rust
|
| 243 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 244 |
+
else
|
| 245 |
+
python3 /fuzz-introspector/src/main.py light
|
| 246 |
+
|
| 247 |
+
# Make a copy of the light. This is needed because we run two versions of
|
| 248 |
+
# introspector: one based on pure statis analysis and one based on
|
| 249 |
+
# regular LTO.
|
| 250 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
# Move coverage report.
|
| 254 |
+
if [ -d "$OUT/textcov_reports" ]
|
| 255 |
+
then
|
| 256 |
+
find $OUT/textcov_reports/ -name "*.covreport" -exec cp {} $SRC/inspector/ \;
|
| 257 |
+
find $OUT/textcov_reports/ -name "*.json" -exec cp {} $SRC/inspector/ \;
|
| 258 |
+
fi
|
| 259 |
+
|
| 260 |
+
# Make fuzz-introspector HTML report using light approach.
|
| 261 |
+
REPORT_ARGS="--name=$PROJECT_NAME"
|
| 262 |
+
|
| 263 |
+
# Only pass coverage_url when COVERAGE_URL is set (in cloud builds)
|
| 264 |
+
if [[ ! -z "${COVERAGE_URL+x}" ]]; then
|
| 265 |
+
REPORT_ARGS="$REPORT_ARGS --coverage-url=${COVERAGE_URL}"
|
| 266 |
+
fi
|
| 267 |
+
|
| 268 |
+
# Run pure static analysis fuzz introspector
|
| 269 |
+
fuzz-introspector full --target-dir=$SRC \
|
| 270 |
+
--language=${FUZZING_LANGUAGE} \
|
| 271 |
+
--out-dir=$SRC/inspector \
|
| 272 |
+
${REPORT_ARGS}
|
| 273 |
+
fi
|
| 274 |
+
|
| 275 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 276 |
+
fi
|
| 277 |
+
|
| 278 |
+
echo "---------------------------------------------------------------"
|
| 279 |
+
echo "CC=$CC"
|
| 280 |
+
echo "CXX=$CXX"
|
| 281 |
+
echo "CFLAGS=$CFLAGS"
|
| 282 |
+
echo "CXXFLAGS=$CXXFLAGS"
|
| 283 |
+
echo "RUSTFLAGS=$RUSTFLAGS"
|
| 284 |
+
echo "---------------------------------------------------------------"
|
| 285 |
+
|
| 286 |
+
if [ "${OSS_FUZZ_ON_DEMAND}" != "0" ]; then
|
| 287 |
+
fuzzbench_build
|
| 288 |
+
cp $(which llvm-symbolizer) $OUT/
|
| 289 |
+
exit 0
|
| 290 |
+
fi
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
if [[ ! -z "${CAPTURE_REPLAY_SCRIPT-}" ]]; then
|
| 294 |
+
# Capture a replaying build script which can be used for replaying the build
|
| 295 |
+
# after a vanilla build. This script is meant to be used in a cached
|
| 296 |
+
# container.
|
| 297 |
+
python3 -m pip install bashlex
|
| 298 |
+
python3 /usr/local/bin/bash_parser.py $SRC/build.sh
|
| 299 |
+
fi
|
| 300 |
+
|
| 301 |
+
# Prepare the build command to run the project's build script.
|
| 302 |
+
if [[ ! -z "${REPLAY_ENABLED-}" ]]; then
|
| 303 |
+
# If this is a replay, then use replay_build.sh. This is expected to be
|
| 304 |
+
# running in a cached container where a build has already happened prior.
|
| 305 |
+
BUILD_CMD="bash -eux $SRC/replay_build.sh"
|
| 306 |
+
else
|
| 307 |
+
BUILD_CMD="bash -eux $SRC/build.sh"
|
| 308 |
+
fi
|
| 309 |
+
|
| 310 |
+
# Set +u temporarily to continue even if GOPATH and OSSFUZZ_RUSTPATH are undefined.
|
| 311 |
+
set +u
|
| 312 |
+
# We need to preserve source code files for generating a code coverage report.
|
| 313 |
+
# We need exact files that were compiled, so copy both $SRC and $WORK dirs.
|
| 314 |
+
COPY_SOURCES_CMD="cp -rL --parents $SRC $WORK /usr/include /usr/local/include $GOPATH $OSSFUZZ_RUSTPATH /rustc $OUT"
|
| 315 |
+
set -u
|
| 316 |
+
|
| 317 |
+
if [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 318 |
+
# Copy rust std lib to its path with a hash.
|
| 319 |
+
export rustch=`rustc --version --verbose | grep commit-hash | cut -d' ' -f2`
|
| 320 |
+
mkdir -p /rustc/$rustch/
|
| 321 |
+
export rustdef=`rustup toolchain list | grep default | cut -d' ' -f1`
|
| 322 |
+
cp -r /rust/rustup/toolchains/$rustdef/lib/rustlib/src/rust/library/ /rustc/$rustch/
|
| 323 |
+
fi
|
| 324 |
+
|
| 325 |
+
if [ "${BUILD_UID-0}" -ne "0" ]; then
|
| 326 |
+
adduser -u $BUILD_UID --disabled-password --gecos '' builder
|
| 327 |
+
chown -R builder $SRC $OUT $WORK
|
| 328 |
+
su -c "$BUILD_CMD" builder
|
| 329 |
+
if [ "$SANITIZER" = "coverage" ]; then
|
| 330 |
+
# Some directories have broken symlinks (e.g. honggfuzz), ignore the errors.
|
| 331 |
+
su -c "$COPY_SOURCES_CMD" builder 2>/dev/null || true
|
| 332 |
+
fi
|
| 333 |
+
else
|
| 334 |
+
$BUILD_CMD
|
| 335 |
+
if [ "$SANITIZER" = "coverage" ]; then
|
| 336 |
+
# Some directories have broken symlinks (e.g. honggfuzz), ignore the errors.
|
| 337 |
+
$COPY_SOURCES_CMD 2>/dev/null || true
|
| 338 |
+
fi
|
| 339 |
+
fi
|
| 340 |
+
|
| 341 |
+
if [ "$SANITIZER" = "introspector" ] || [ "$RUST_SANITIZER" = "introspector" ]; then
|
| 342 |
+
unset CXXFLAGS
|
| 343 |
+
unset CFLAGS
|
| 344 |
+
export G_ANALYTICS_TAG="G-8WTFM1Y62J"
|
| 345 |
+
|
| 346 |
+
# If we get to here, it means the e.g. LTO had no problems and succeeded.
|
| 347 |
+
# TO this end, we wlil restore the original light analysis and used the
|
| 348 |
+
# LTO processing itself.
|
| 349 |
+
rm -rf $SRC/inspector
|
| 350 |
+
cp -rf /tmp/inspector-saved $SRC/inspector
|
| 351 |
+
|
| 352 |
+
cd /fuzz-introspector/src
|
| 353 |
+
python3 -m pip install -e .
|
| 354 |
+
cd /src/
|
| 355 |
+
|
| 356 |
+
if [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 357 |
+
# Restore the sanitizer flag for rust
|
| 358 |
+
export SANITIZER="introspector"
|
| 359 |
+
fi
|
| 360 |
+
|
| 361 |
+
mkdir -p $SRC/inspector
|
| 362 |
+
find $SRC/ -name "fuzzerLogFile-*.data" -exec cp {} $SRC/inspector/ \;
|
| 363 |
+
find $SRC/ -name "fuzzerLogFile-*.data.yaml" -exec cp {} $SRC/inspector/ \;
|
| 364 |
+
find $SRC/ -name "fuzzerLogFile-*.data.debug_*" -exec cp {} $SRC/inspector/ \;
|
| 365 |
+
find $SRC/ -name "allFunctionsWithMain-*.yaml" -exec cp {} $SRC/inspector/ \;
|
| 366 |
+
|
| 367 |
+
# Move coverage report.
|
| 368 |
+
if [ -d "$OUT/textcov_reports" ]
|
| 369 |
+
then
|
| 370 |
+
find $OUT/textcov_reports/ -name "*.covreport" -exec cp {} $SRC/inspector/ \;
|
| 371 |
+
find $OUT/textcov_reports/ -name "*.json" -exec cp {} $SRC/inspector/ \;
|
| 372 |
+
fi
|
| 373 |
+
|
| 374 |
+
cd $SRC/inspector
|
| 375 |
+
|
| 376 |
+
# Make fuzz-introspector HTML report.
|
| 377 |
+
REPORT_ARGS="--name=$PROJECT_NAME"
|
| 378 |
+
# Only pass coverage_url when COVERAGE_URL is set (in cloud builds)
|
| 379 |
+
if [[ ! -z "${COVERAGE_URL+x}" ]]; then
|
| 380 |
+
REPORT_ARGS="$REPORT_ARGS --coverage-url=${COVERAGE_URL}"
|
| 381 |
+
fi
|
| 382 |
+
|
| 383 |
+
# Do different things depending on languages
|
| 384 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 385 |
+
echo "GOING python route"
|
| 386 |
+
set -x
|
| 387 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
|
| 388 |
+
REPORT_ARGS="$REPORT_ARGS --language=python"
|
| 389 |
+
fuzz-introspector report $REPORT_ARGS
|
| 390 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 391 |
+
elif [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 392 |
+
echo "GOING jvm route"
|
| 393 |
+
set -x
|
| 394 |
+
find $OUT/ -name "jacoco.xml" -exec cp {} $SRC/inspector/ \;
|
| 395 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC --out-dir=$SRC/inspector"
|
| 396 |
+
REPORT_ARGS="$REPORT_ARGS --language=jvm"
|
| 397 |
+
fuzz-introspector full $REPORT_ARGS
|
| 398 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 399 |
+
elif [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 400 |
+
echo "GOING rust route"
|
| 401 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC --out-dir=$SRC/inspector"
|
| 402 |
+
REPORT_ARGS="$REPORT_ARGS --language=rust"
|
| 403 |
+
fuzz-introspector full $REPORT_ARGS
|
| 404 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 405 |
+
else
|
| 406 |
+
# C/C++
|
| 407 |
+
mkdir -p $SRC/inspector
|
| 408 |
+
# Correlate fuzzer binaries to fuzz-introspector's raw data
|
| 409 |
+
fuzz-introspector correlate --binaries-dir=$OUT/
|
| 410 |
+
|
| 411 |
+
# Generate fuzz-introspector HTML report, this generates
|
| 412 |
+
# the file exe_to_fuzz_introspector_logs.yaml
|
| 413 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
|
| 414 |
+
# Use the just-generated correlation file
|
| 415 |
+
REPORT_ARGS="$REPORT_ARGS --correlation-file=exe_to_fuzz_introspector_logs.yaml"
|
| 416 |
+
fuzz-introspector report $REPORT_ARGS
|
| 417 |
+
|
| 418 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 419 |
+
fi
|
| 420 |
+
fi
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_centipede
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo "Skipping compilation; using precompiled centipede"
|
| 19 |
+
|
| 20 |
+
if [[ "$SANITIZER" == 'none' ]]; then
|
| 21 |
+
cp "$CENTIPEDE_BIN_DIR/centipede" "$OUT"
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
cp "$CENTIPEDE_BIN_DIR/libcentipede_runner.pic.a" "$LIB_FUZZING_ENGINE"
|
| 25 |
+
|
| 26 |
+
export CENTIPEDE_FLAGS=`cat "$SRC/fuzztest/centipede/clang-flags.txt" | tr '\n' ' '`
|
| 27 |
+
export LIBRARIES_FLAGS="-Wno-unused-command-line-argument -Wl,-ldl -Wl,-lrt -Wl,-lpthread -Wl,$SRC/fuzztest/centipede/weak.o"
|
| 28 |
+
|
| 29 |
+
export CFLAGS="$CFLAGS $CENTIPEDE_FLAGS $LIBRARIES_FLAGS"
|
| 30 |
+
export CXXFLAGS="$CXXFLAGS $CENTIPEDE_FLAGS $LIBRARIES_FLAGS"
|
| 31 |
+
|
| 32 |
+
echo 'done.'
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_fuzztests.sh
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
set -x
|
| 19 |
+
|
| 20 |
+
# In order to identify fuzztest test case "bazel query" is used to search
|
| 21 |
+
# the project. A search of the entire project is done with a default "...",
|
| 22 |
+
# however, some projects may fail to, or have very long processing time, if
|
| 23 |
+
# searching the entire project. Additionally, it may include fuzzers in
|
| 24 |
+
# dependencies, which should not be build as part of a given project.
|
| 25 |
+
# Tensorflow is an example project that will fail when the entire project is
|
| 26 |
+
# queried. FUZZTEST_TARGET_FOLDER makes it posible to specify the folder
|
| 27 |
+
# where fuzztest fuzzers should be search for. FUZZTEST_TARGET_FOLDER is passed
|
| 28 |
+
# to "bazel query" below.
|
| 29 |
+
if [[ ${FUZZTEST_TARGET_FOLDER:-"unset"} == "unset" ]];
|
| 30 |
+
then
|
| 31 |
+
export TARGET_FOLDER="..."
|
| 32 |
+
else
|
| 33 |
+
TARGET_FOLDER=${FUZZTEST_TARGET_FOLDER}
|
| 34 |
+
fi
|
| 35 |
+
|
| 36 |
+
BUILD_ARGS="--config=oss-fuzz --subcommands"
|
| 37 |
+
if [[ ${FUZZTEST_EXTRA_ARGS:-"unset"} != "unset" ]];
|
| 38 |
+
then
|
| 39 |
+
BUILD_ARGS="$BUILD_ARGS ${FUZZTEST_EXTRA_ARGS}"
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
# Trigger setup_configs rule of fuzztest as it generates the necessary
|
| 43 |
+
# configuration file based on OSS-Fuzz environment variables.
|
| 44 |
+
bazel run @com_google_fuzztest//bazel:setup_configs >> /etc/bazel.bazelrc
|
| 45 |
+
|
| 46 |
+
# Bazel target names of the fuzz binaries.
|
| 47 |
+
FUZZ_TEST_BINARIES=$(bazel query "kind(\"cc_test\", rdeps(${TARGET_FOLDER}, @com_google_fuzztest//fuzztest:fuzztest_gtest_main))")
|
| 48 |
+
|
| 49 |
+
# Bazel output paths of the fuzz binaries.
|
| 50 |
+
FUZZ_TEST_BINARIES_OUT_PATHS=$(bazel cquery "kind(\"cc_test\", rdeps(${TARGET_FOLDER}, @com_google_fuzztest//fuzztest:fuzztest_gtest_main))" --output=files)
|
| 51 |
+
|
| 52 |
+
# Build the project and fuzz binaries
|
| 53 |
+
# Expose `FUZZTEST_EXTRA_TARGETS` environment variable, in the event a project
|
| 54 |
+
# includes non-FuzzTest fuzzers then this can be used to compile these in the
|
| 55 |
+
# same `bazel build` command as when building the FuzzTest fuzzers.
|
| 56 |
+
# This is to avoid having to call `bazel build` twice.
|
| 57 |
+
bazel build $BUILD_ARGS -- ${FUZZ_TEST_BINARIES[*]} ${FUZZTEST_EXTRA_TARGETS:-}
|
| 58 |
+
|
| 59 |
+
# Iterate the fuzz binaries and list each fuzz entrypoint in the binary. For
|
| 60 |
+
# each entrypoint create a wrapper script that calls into the binaries the
|
| 61 |
+
# given entrypoint as argument.
|
| 62 |
+
# The scripts will be named:
|
| 63 |
+
# {binary_name}@{fuzztest_entrypoint}
|
| 64 |
+
for fuzz_main_file in $FUZZ_TEST_BINARIES_OUT_PATHS; do
|
| 65 |
+
FUZZ_TESTS=$($fuzz_main_file --list_fuzz_tests)
|
| 66 |
+
cp ${fuzz_main_file} $OUT/
|
| 67 |
+
fuzz_basename=$(basename $fuzz_main_file)
|
| 68 |
+
chmod -x $OUT/$fuzz_basename
|
| 69 |
+
for fuzz_entrypoint in $FUZZ_TESTS; do
|
| 70 |
+
TARGET_FUZZER="${fuzz_basename}@$fuzz_entrypoint"
|
| 71 |
+
|
| 72 |
+
# Write executer script
|
| 73 |
+
echo "#!/bin/sh
|
| 74 |
+
# LLVMFuzzerTestOneInput for fuzzer detection.
|
| 75 |
+
this_dir=\$(dirname \"\$0\")
|
| 76 |
+
chmod +x \$this_dir/$fuzz_basename
|
| 77 |
+
\$this_dir/$fuzz_basename --fuzz=$fuzz_entrypoint -- \$@" > $OUT/$TARGET_FUZZER
|
| 78 |
+
chmod +x $OUT/$TARGET_FUZZER
|
| 79 |
+
done
|
| 80 |
+
done
|
| 81 |
+
|
| 82 |
+
# Synchronise coverage directory to bazel output artifacts. This is a
|
| 83 |
+
# best-effort basis in that it will include source code in common
|
| 84 |
+
# bazel output folders.
|
| 85 |
+
# For projects that store results in non-standard folders or want to
|
| 86 |
+
# manage what code to include in the coverage report more specifically,
|
| 87 |
+
# the FUZZTEST_DO_SYNC environment variable is made available. Projects
|
| 88 |
+
# can then implement a custom way of synchronising source code with the
|
| 89 |
+
# coverage build. Set FUZZTEST_DO_SYNC to something other than "yes" and
|
| 90 |
+
# no effort will be made to automatically synchronise the source code with
|
| 91 |
+
# the code coverage visualisation utility.
|
| 92 |
+
if [[ "$SANITIZER" = "coverage" && ${FUZZTEST_DO_SYNC:-"yes"} == "yes" ]]
|
| 93 |
+
then
|
| 94 |
+
# Synchronize bazel source files to coverage collection.
|
| 95 |
+
declare -r REMAP_PATH="${OUT}/proc/self/cwd"
|
| 96 |
+
mkdir -p "${REMAP_PATH}"
|
| 97 |
+
|
| 98 |
+
# Synchronize the folder bazel-BAZEL_OUT_PROJECT.
|
| 99 |
+
declare -r RSYNC_FILTER_ARGS=("--include" "*.h" "--include" "*.cc" "--include" \
|
| 100 |
+
"*.hpp" "--include" "*.cpp" "--include" "*.c" "--include" "*/" "--include" "*.inc" \
|
| 101 |
+
"--exclude" "*")
|
| 102 |
+
|
| 103 |
+
project_folders="$(find . -name 'bazel-*' -type l -printf '%P\n' | \
|
| 104 |
+
grep -v -x -F \
|
| 105 |
+
-e 'bazel-bin' \
|
| 106 |
+
-e 'bazel-testlogs')"
|
| 107 |
+
for link in $project_folders; do
|
| 108 |
+
if [[ -d "${PWD}"/$link/external ]]
|
| 109 |
+
then
|
| 110 |
+
rsync -avLk "${RSYNC_FILTER_ARGS[@]}" "${PWD}"/$link/external "${REMAP_PATH}"
|
| 111 |
+
fi
|
| 112 |
+
# k8-opt is a common path for storing bazel output artifacts, e.g. bazel-out/k8-opt.
|
| 113 |
+
# It's the output folder for default amd-64 builds, but projects may specify custom
|
| 114 |
+
# platform output directories, see: https://github.com/bazelbuild/bazel/issues/13818
|
| 115 |
+
# We support the default at the moment, and if a project needs custom synchronizing of
|
| 116 |
+
# output artifacts and code coverage we currently recommend using FUZZTEST_DO_SYNC.
|
| 117 |
+
if [[ -d "${PWD}"/$link/k8-opt ]]
|
| 118 |
+
then
|
| 119 |
+
rsync -avLk "${RSYNC_FILTER_ARGS[@]}" "${PWD}"/$link/k8-opt "${REMAP_PATH}"/$link
|
| 120 |
+
fi
|
| 121 |
+
done
|
| 122 |
+
|
| 123 |
+
# Delete symlinks and sync the current folder.
|
| 124 |
+
find . -type l -ls -delete
|
| 125 |
+
rsync -av ${PWD}/ "${REMAP_PATH}"
|
| 126 |
+
fi
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_honggfuzz
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo "Skipping compilation; using precompiled honggfuzz"
|
| 19 |
+
|
| 20 |
+
cp $SRC/honggfuzz/honggfuzz.a $LIB_FUZZING_ENGINE
|
| 21 |
+
cp $SRC/honggfuzz/honggfuzz $OUT/
|
| 22 |
+
|
| 23 |
+
# Set flags necessary for netdriver compilation.
|
| 24 |
+
export LIB_HFND="-Wl,-u,LIBHFNETDRIVER_module_netdriver -Wl,--start-group $SRC/honggfuzz/libhfnetdriver/libhfnetdriver.a $SRC/honggfuzz/libhfcommon/libhfcommon.a -Wl,--end-group"
|
| 25 |
+
|
| 26 |
+
export HFND_CXXFLAGS='-DHFND_FUZZING_ENTRY_FUNCTION_CXX(x,y)=extern const char* LIBHFNETDRIVER_module_netdriver;const char** LIBHFNETDRIVER_tmp1 = &LIBHFNETDRIVER_module_netdriver;extern "C" int HonggfuzzNetDriver_main(x,y);int HonggfuzzNetDriver_main(x,y)'
|
| 27 |
+
export HFND_CFLAGS='-DHFND_FUZZING_ENTRY_FUNCTION(x,y)=extern const char* LIBHFNETDRIVER_module_netdriver;const char** LIBHFNETDRIVER_tmp1 = &LIBHFNETDRIVER_module_netdriver;int HonggfuzzNetDriver_main(x,y);int HonggfuzzNetDriver_main(x,y)'
|
| 28 |
+
|
| 29 |
+
# Custom coverage flags, roughly in sync with:
|
| 30 |
+
# https://github.com/google/honggfuzz/blob/oss-fuzz/hfuzz_cc/hfuzz-cc.c
|
| 31 |
+
export COVERAGE_FLAGS="-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp"
|
| 32 |
+
|
| 33 |
+
echo " done."
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_javascript_fuzzer
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2023 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
project=$1
|
| 19 |
+
# Path the fuzz target source file relative to the project's root.
|
| 20 |
+
fuzz_target=$2
|
| 21 |
+
# Arguments to pass to Jazzer.js
|
| 22 |
+
jazzerjs_args=${@:3}
|
| 23 |
+
|
| 24 |
+
# Copy source code into the $OUT directory and install Jazzer.js into the project.
|
| 25 |
+
if [ ! -d $OUT/$project ]; then
|
| 26 |
+
cp -r $SRC/$project $OUT/$project
|
| 27 |
+
fi
|
| 28 |
+
|
| 29 |
+
fuzzer_basename=$(basename -s .js $fuzz_target)
|
| 30 |
+
|
| 31 |
+
# Create an execution wrapper that executes Jazzer.js with the correct arguments.
|
| 32 |
+
echo "#!/bin/bash
|
| 33 |
+
# LLVMFuzzerTestOneInput so that the wrapper script is recognized as a fuzz target for 'check_build'.
|
| 34 |
+
project_dir=\$(dirname \"\$0\")/$project
|
| 35 |
+
\$project_dir/node_modules/@jazzer.js/core/dist/cli.js \$project_dir/$fuzz_target $jazzerjs_args \$JAZZERJS_EXTRA_ARGS -- \$@" > $OUT/$fuzzer_basename
|
| 36 |
+
|
| 37 |
+
chmod +x $OUT/$fuzzer_basename
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/compile_libfuzzer
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo -n "Compiling libFuzzer to $LIB_FUZZING_ENGINE... "
|
| 19 |
+
export LIB_FUZZING_ENGINE="-fsanitize=fuzzer"
|
| 20 |
+
if [ "$FUZZING_LANGUAGE" = "go" ]; then
|
| 21 |
+
export LIB_FUZZING_ENGINE="$LIB_FUZZING_ENGINE $GOPATH/gosigfuzz/gosigfuzz.o"
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
cp /usr/local/lib/clang/*/lib/$ARCHITECTURE-unknown-linux-gnu/libclang_rt.fuzzer.a $LIB_FUZZING_ENGINE_DEPRECATED
|
| 25 |
+
echo " done."
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/debug_afl
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# Source this file for afl++ debug sessions.
|
| 19 |
+
apt-get update
|
| 20 |
+
apt-get install -y strace gdb vim joe psmisc
|
| 21 |
+
|
| 22 |
+
pushd $SRC/aflplusplus > /dev/null
|
| 23 |
+
git checkout dev
|
| 24 |
+
git pull
|
| 25 |
+
test -n "$1" && { git checkout "$1" ; git pull ; }
|
| 26 |
+
CFLAGS_SAVE="$CFLAGS"
|
| 27 |
+
CXXFLAGS_SAVE="$CXXFLAGS"
|
| 28 |
+
unset CFLAGS
|
| 29 |
+
unset CXXFLAGS
|
| 30 |
+
make
|
| 31 |
+
export CFLAGS="$CFLAGS_SAVE"
|
| 32 |
+
export CXXFLAGS="$CXXFLAGS_SAVE"
|
| 33 |
+
popd > /dev/null
|
| 34 |
+
|
| 35 |
+
export ASAN_OPTIONS="detect_leaks=0:symbolize=0:detect_odr_violation=0:abort_on_error=1"
|
| 36 |
+
export AFL_LLVM_LAF_ALL=1
|
| 37 |
+
export AFL_LLVM_CMPLOG=1
|
| 38 |
+
touch "$OUT/afl_cmplog.txt"
|
| 39 |
+
export AFL_LLVM_DICT2FILE=$OUT/afl++.dict
|
| 40 |
+
ulimit -c unlimited
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_deps.sh
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# Install base-builder's dependencies in a architecture-aware way.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
case $(uname -m) in
|
| 22 |
+
x86_64)
|
| 23 |
+
dpkg --add-architecture i386
|
| 24 |
+
;;
|
| 25 |
+
esac
|
| 26 |
+
|
| 27 |
+
apt-get update && \
|
| 28 |
+
apt-get install -y \
|
| 29 |
+
binutils-dev \
|
| 30 |
+
build-essential \
|
| 31 |
+
curl \
|
| 32 |
+
wget \
|
| 33 |
+
git \
|
| 34 |
+
jq \
|
| 35 |
+
patchelf \
|
| 36 |
+
rsync \
|
| 37 |
+
subversion \
|
| 38 |
+
zip
|
| 39 |
+
|
| 40 |
+
case $(uname -m) in
|
| 41 |
+
x86_64)
|
| 42 |
+
apt-get install -y libc6-dev-i386
|
| 43 |
+
;;
|
| 44 |
+
esac
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_java.sh
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# Install OpenJDK 17 and trim its size by removing unused components. This enables using Jazzer's mutation framework.
|
| 19 |
+
cd /tmp
|
| 20 |
+
curl --silent -L -O https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz && \
|
| 21 |
+
mkdir -p $JAVA_HOME
|
| 22 |
+
tar -xz --strip-components=1 -f openjdk-17.0.2_linux-x64_bin.tar.gz --directory $JAVA_HOME && \
|
| 23 |
+
rm -f openjdk-17.0.2_linux-x64_bin.tar.gz
|
| 24 |
+
rm -rf $JAVA_HOME/jmods $JAVA_HOME/lib/src.zip
|
| 25 |
+
|
| 26 |
+
# Install OpenJDK 15 and trim its size by removing unused components. Some projects only run with Java 15.
|
| 27 |
+
curl --silent -L -O https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-x64_bin.tar.gz && \
|
| 28 |
+
mkdir -p $JAVA_15_HOME
|
| 29 |
+
tar -xz --strip-components=1 -f openjdk-15.0.2_linux-x64_bin.tar.gz --directory $JAVA_15_HOME && \
|
| 30 |
+
rm -f openjdk-15.0.2_linux-x64_bin.tar.gz
|
| 31 |
+
rm -rf $JAVA_15_HOME/jmods $JAVA_15_HOME/lib/src.zip
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_python.sh
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo "ATHERIS INSTALL"
|
| 19 |
+
unset CFLAGS CXXFLAGS
|
| 20 |
+
# PYI_STATIC_ZLIB=1 is needed for installing pyinstaller 5.0
|
| 21 |
+
export PYI_STATIC_ZLIB=1
|
| 22 |
+
LIBFUZZER_LIB=$( echo /usr/local/lib/clang/*/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer_no_main.a ) pip3 install -v --no-cache-dir "atheris>=2.3.0" "pyinstaller==6.10.0" "setuptools==72.1.0" "coverage==6.3.2"
|
| 23 |
+
rm -rf /tmp/*
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_ruby.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Copyright 2024 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
apt update
|
| 19 |
+
apt install -y lsb-release software-properties-common gnupg2 binutils xz-utils libyaml-dev
|
| 20 |
+
gpg2 --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
| 21 |
+
curl -sSL https://get.rvm.io | bash
|
| 22 |
+
|
| 23 |
+
. /etc/profile.d/rvm.sh
|
| 24 |
+
|
| 25 |
+
rvm install ruby-3.3.1
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/install_rust.sh
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=$RUSTUP_TOOLCHAIN --profile=minimal
|
| 19 |
+
cargo install cargo-fuzz --locked && rm -rf /rust/registry
|
| 20 |
+
# Needed to recompile rust std library for MSAN
|
| 21 |
+
rustup component add rust-src
|
| 22 |
+
cp -r /usr/local/lib/x86_64-unknown-linux-gnu/* /usr/local/lib/
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/ossfuzz_coverage_runner.go
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package mypackagebeingfuzzed
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"io/ioutil"
|
| 19 |
+
"os"
|
| 20 |
+
"runtime/pprof"
|
| 21 |
+
"testing"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func TestFuzzCorpus(t *testing.T) {
|
| 25 |
+
dir := os.Getenv("FUZZ_CORPUS_DIR")
|
| 26 |
+
if dir == "" {
|
| 27 |
+
t.Logf("No fuzzing corpus directory set")
|
| 28 |
+
return
|
| 29 |
+
}
|
| 30 |
+
infos, err := ioutil.ReadDir(dir)
|
| 31 |
+
if err != nil {
|
| 32 |
+
t.Logf("Not fuzzing corpus directory %s", err)
|
| 33 |
+
return
|
| 34 |
+
}
|
| 35 |
+
filename := ""
|
| 36 |
+
defer func() {
|
| 37 |
+
if r := recover(); r != nil {
|
| 38 |
+
t.Error("Fuzz panicked in "+filename, r)
|
| 39 |
+
}
|
| 40 |
+
}()
|
| 41 |
+
profname := os.Getenv("FUZZ_PROFILE_NAME")
|
| 42 |
+
if profname != "" {
|
| 43 |
+
f, err := os.Create(profname + ".cpu.prof")
|
| 44 |
+
if err != nil {
|
| 45 |
+
t.Logf("error creating profile file %s\n", err)
|
| 46 |
+
} else {
|
| 47 |
+
_ = pprof.StartCPUProfile(f)
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
for i := range infos {
|
| 51 |
+
filename = dir + infos[i].Name()
|
| 52 |
+
data, err := ioutil.ReadFile(filename)
|
| 53 |
+
if err != nil {
|
| 54 |
+
t.Error("Failed to read corpus file", err)
|
| 55 |
+
}
|
| 56 |
+
FuzzFunction(data)
|
| 57 |
+
}
|
| 58 |
+
if profname != "" {
|
| 59 |
+
pprof.StopCPUProfile()
|
| 60 |
+
f, err := os.Create(profname + ".heap.prof")
|
| 61 |
+
if err != nil {
|
| 62 |
+
t.Logf("error creating heap profile file %s\n", err)
|
| 63 |
+
}
|
| 64 |
+
if err = pprof.WriteHeapProfile(f); err != nil {
|
| 65 |
+
t.Logf("error writing heap profile file %s\n", err)
|
| 66 |
+
}
|
| 67 |
+
f.Close()
|
| 68 |
+
}
|
| 69 |
+
}
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/precompile_centipede
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo -n "Precompiling centipede"
|
| 19 |
+
|
| 20 |
+
# Build Centipede with bazel.
|
| 21 |
+
cd "$SRC/fuzztest/centipede/"
|
| 22 |
+
apt-get update && apt-get install libssl-dev -y
|
| 23 |
+
unset CXXFLAGS CFLAGS
|
| 24 |
+
# We need to use an older version of BAZEL because fuzztest relies on WORKSPACE
|
| 25 |
+
# Ref: https://github.com/google/oss-fuzz/pull/12838#issue-2733821058
|
| 26 |
+
export USE_BAZEL_VERSION=7.4.0
|
| 27 |
+
echo 'build --cxxopt=-stdlib=libc++ --linkopt=-lc++' >> /tmp/centipede.bazelrc
|
| 28 |
+
bazel --bazelrc=/tmp/centipede.bazelrc build -c opt :all
|
| 29 |
+
unset USE_BAZEL_VERSION
|
| 30 |
+
|
| 31 |
+
# Prepare the weak symbols:
|
| 32 |
+
# This is necessary because we compile the target binary and the intermediate
|
| 33 |
+
# auxiliary binaries with the same cflags. The auxiliary binaries do not need
|
| 34 |
+
# data-flow tracing flags, but will still throw errors when they cannot find
|
| 35 |
+
# the corresponding functions.
|
| 36 |
+
# The weak symbols provides fake implementations for intermediate binaries.
|
| 37 |
+
$CXX "$SRC/fuzztest/centipede/weak_sancov_stubs.cc" -c -o "$SRC/fuzztest/centipede/weak.o"
|
| 38 |
+
|
| 39 |
+
echo 'Removing extra stuff leftover to avoid bloating image.'
|
| 40 |
+
|
| 41 |
+
rm -rf /clang-*.tgz /clang
|
| 42 |
+
|
| 43 |
+
BAZEL_BIN_REAL_DIR=$(readlink -f $CENTIPEDE_BIN_DIR)
|
| 44 |
+
rm -rf $CENTIPEDE_BIN_DIR
|
| 45 |
+
mkdir -p $CENTIPEDE_BIN_DIR
|
| 46 |
+
mv $BAZEL_BIN_REAL_DIR/centipede/{centipede,libcentipede_runner.pic.a} $CENTIPEDE_BIN_DIR
|
| 47 |
+
rm -rf /root/.cache
|
| 48 |
+
|
| 49 |
+
echo 'Done.'
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-builder/srcmap
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# Deterimine srcmap of checked out source code
|
| 19 |
+
|
| 20 |
+
SRCMAP=$(tempfile)
|
| 21 |
+
echo "{}" > $SRCMAP
|
| 22 |
+
|
| 23 |
+
# $1 - json file, $2 - jq program
|
| 24 |
+
function jq_inplace() {
|
| 25 |
+
F=$(tempfile) && cat $1 | jq "$2" > $F && mv $F $1
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
PATHS_TO_SCAN="$SRC"
|
| 29 |
+
|
| 30 |
+
if [[ $FUZZING_LANGUAGE == "go" ]]; then
|
| 31 |
+
PATHS_TO_SCAN="$PATHS_TO_SCAN $GOPATH"
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
# Git
|
| 35 |
+
for DOT_GIT_DIR in $(find $PATHS_TO_SCAN -name ".git" -type d); do
|
| 36 |
+
GIT_DIR=$(dirname $DOT_GIT_DIR)
|
| 37 |
+
cd $GIT_DIR
|
| 38 |
+
GIT_URL=$(git config --get remote.origin.url)
|
| 39 |
+
GIT_REV=$(git rev-parse HEAD)
|
| 40 |
+
jq_inplace $SRCMAP ".\"$GIT_DIR\" = { type: \"git\", url: \"$GIT_URL\", rev: \"$GIT_REV\" }"
|
| 41 |
+
done
|
| 42 |
+
|
| 43 |
+
# Subversion
|
| 44 |
+
for DOT_SVN_DIR in $(find $PATHS_TO_SCAN -name ".svn" -type d); do
|
| 45 |
+
SVN_DIR=$(dirname $DOT_SVN_DIR)
|
| 46 |
+
cd $SVN_DIR
|
| 47 |
+
SVN_URL=$(svn info | grep "^URL:" | sed 's/URL: //g')
|
| 48 |
+
SVN_REV=$(svn info -r HEAD | grep "^Revision:" | sed 's/Revision: //g')
|
| 49 |
+
jq_inplace $SRCMAP ".\"$SVN_DIR\" = { type: \"svn\", url: \"$SVN_URL\", rev: \"$SVN_REV\" }"
|
| 50 |
+
done
|
| 51 |
+
|
| 52 |
+
# Mercurial
|
| 53 |
+
for DOT_HG_DIR in $(find $PATHS_TO_SCAN -name ".hg" -type d); do
|
| 54 |
+
HG_DIR=$(dirname $DOT_HG_DIR)
|
| 55 |
+
cd $HG_DIR
|
| 56 |
+
HG_URL=$(hg paths default)
|
| 57 |
+
HG_REV=$(hg --debug id -r. -i)
|
| 58 |
+
jq_inplace $SRCMAP ".\"$HG_DIR\" = { type: \"hg\", url: \"$HG_URL\", rev: \"$HG_REV\" }"
|
| 59 |
+
done
|
| 60 |
+
|
| 61 |
+
if [ "${OSSFUZZ_REVISION-}" != "" ]; then
|
| 62 |
+
jq_inplace $SRCMAP ".\"/src\" = { type: \"git\", url: \"https://github.com/google/oss-fuzz.git\", rev: \"$OSSFUZZ_REVISION\" }"
|
| 63 |
+
fi
|
| 64 |
+
|
| 65 |
+
cat $SRCMAP
|
| 66 |
+
rm $SRCMAP
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/Dockerfile
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2016 Google Inc.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
#
|
| 15 |
+
################################################################################
|
| 16 |
+
|
| 17 |
+
# Build rust stuff in its own image. We only need the resulting binaries.
|
| 18 |
+
# Keeping the rust toolchain in the image wastes 1 GB.
|
| 19 |
+
ARG IMG_TAG=latest
|
| 20 |
+
FROM ghcr.io/aixcc-finals/base-image:${IMG_TAG} as temp-runner-binary-builder
|
| 21 |
+
|
| 22 |
+
RUN apt-get update && apt-get install -y cargo libyaml-dev
|
| 23 |
+
RUN cargo install rustfilt
|
| 24 |
+
|
| 25 |
+
# Using multi-stage build to copy some LLVM binaries needed in the runner image.
|
| 26 |
+
FROM ghcr.io/aixcc-finals/base-clang:${IMG_TAG} AS base-clang
|
| 27 |
+
FROM ghcr.io/aixcc-finals/base-builder-ruby:${IMG_TAG} AS base-ruby
|
| 28 |
+
|
| 29 |
+
# The base builder image compiles a specific Python version. Using a multi-stage build
|
| 30 |
+
# to copy that same Python interpreter into the runner image saves build time and keeps
|
| 31 |
+
# the Python versions in sync.
|
| 32 |
+
FROM ghcr.io/aixcc-finals/base-builder:${IMG_TAG} AS base-builder
|
| 33 |
+
|
| 34 |
+
# Real image that will be used later.
|
| 35 |
+
FROM ghcr.io/aixcc-finals/base-image:${IMG_TAG}
|
| 36 |
+
|
| 37 |
+
COPY --from=temp-runner-binary-builder /root/.cargo/bin/rustfilt /usr/local/bin
|
| 38 |
+
|
| 39 |
+
# Copy the binaries needed for code coverage and crash symbolization.
|
| 40 |
+
COPY --from=base-clang /usr/local/bin/llvm-cov \
|
| 41 |
+
/usr/local/bin/llvm-profdata \
|
| 42 |
+
/usr/local/bin/llvm-symbolizer \
|
| 43 |
+
/usr/local/bin/
|
| 44 |
+
|
| 45 |
+
# Copy the pre-compiled Python binaries and libraries
|
| 46 |
+
COPY --from=base-builder /usr/local/bin/python3.10 /usr/local/bin/python3.10
|
| 47 |
+
COPY --from=base-builder /usr/local/lib/libpython3.10.so.1.0 /usr/local/lib/libpython3.10.so.1.0
|
| 48 |
+
COPY --from=base-builder /usr/local/include/python3.10 /usr/local/include/python3.10
|
| 49 |
+
COPY --from=base-builder /usr/local/lib/python3.10 /usr/local/lib/python3.10
|
| 50 |
+
COPY --from=base-builder /usr/local/bin/pip3 /usr/local/bin/pip3
|
| 51 |
+
|
| 52 |
+
# Create symbolic links to ensure compatibility
|
| 53 |
+
RUN ldconfig && \
|
| 54 |
+
ln -s /usr/local/bin/python3.10 /usr/local/bin/python3 && \
|
| 55 |
+
ln -s /usr/local/bin/python3.10 /usr/local/bin/python
|
| 56 |
+
|
| 57 |
+
COPY install_deps.sh /
|
| 58 |
+
RUN /install_deps.sh && rm /install_deps.sh
|
| 59 |
+
|
| 60 |
+
ENV CODE_COVERAGE_SRC=/opt/code_coverage
|
| 61 |
+
# Pin coverage to the same as in the base builder:
|
| 62 |
+
# https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/install_python.sh#L22
|
| 63 |
+
RUN git clone https://chromium.googlesource.com/chromium/src/tools/code_coverage $CODE_COVERAGE_SRC && \
|
| 64 |
+
cd /opt/code_coverage && \
|
| 65 |
+
git checkout edba4873b5e8a390e977a64c522db2df18a8b27d && \
|
| 66 |
+
pip3 install wheel && \
|
| 67 |
+
# If version "Jinja2==2.10" is in requirements.txt, bump it to a patch version that
|
| 68 |
+
# supports upgrading its MarkupSafe dependency to a Python 3.10 compatible release:
|
| 69 |
+
sed -i 's/Jinja2==2.10/Jinja2==2.10.3/' requirements.txt && \
|
| 70 |
+
pip3 install -r requirements.txt && \
|
| 71 |
+
pip3 install MarkupSafe==2.0.1 && \
|
| 72 |
+
pip3 install coverage==6.3.2
|
| 73 |
+
|
| 74 |
+
# Default environment options for various sanitizers.
|
| 75 |
+
# Note that these match the settings used in ClusterFuzz and
|
| 76 |
+
# shouldn't be changed unless a corresponding change is made on
|
| 77 |
+
# ClusterFuzz side as well.
|
| 78 |
+
ENV ASAN_OPTIONS="alloc_dealloc_mismatch=0:allocator_may_return_null=1:allocator_release_to_os_interval_ms=500:check_malloc_usable_size=0:detect_container_overflow=1:detect_odr_violation=0:detect_leaks=1:detect_stack_use_after_return=1:fast_unwind_on_fatal=0:handle_abort=1:handle_segv=1:handle_sigill=1:max_uar_stack_size_log=16:print_scariness=1:quarantine_size_mb=10:strict_memcmp=1:strip_path_prefix=/workspace/:symbolize=1:use_sigaltstack=1:dedup_token_length=3"
|
| 79 |
+
ENV MSAN_OPTIONS="print_stats=1:strip_path_prefix=/workspace/:symbolize=1:dedup_token_length=3"
|
| 80 |
+
ENV UBSAN_OPTIONS="print_stacktrace=1:print_summary=1:silence_unsigned_overflow=1:strip_path_prefix=/workspace/:symbolize=1:dedup_token_length=3"
|
| 81 |
+
ENV FUZZER_ARGS="-rss_limit_mb=2560 -timeout=25"
|
| 82 |
+
ENV AFL_FUZZER_ARGS="-m none"
|
| 83 |
+
|
| 84 |
+
# Set up Golang environment variables (copied from /root/.bash_profile).
|
| 85 |
+
ENV GOPATH /root/go
|
| 86 |
+
|
| 87 |
+
# /root/.go/bin is for the standard Go binaries (i.e. go, gofmt, etc).
|
| 88 |
+
# $GOPATH/bin is for the binaries from the dependencies installed via "go get".
|
| 89 |
+
ENV PATH $PATH:$GOPATH/bin
|
| 90 |
+
COPY gocoverage $GOPATH/gocoverage
|
| 91 |
+
|
| 92 |
+
COPY install_go.sh /
|
| 93 |
+
RUN /install_go.sh && rm -rf /install_go.sh /root/.go
|
| 94 |
+
|
| 95 |
+
# Install OpenJDK 15 and trim its size by removing unused components.
|
| 96 |
+
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
| 97 |
+
ENV JAVA_15_HOME=/usr/lib/jvm/java-15-openjdk-amd64
|
| 98 |
+
ENV JVM_LD_LIBRARY_PATH=$JAVA_HOME/lib/server
|
| 99 |
+
ENV PATH=$PATH:$JAVA_HOME/bin
|
| 100 |
+
|
| 101 |
+
COPY install_java.sh /
|
| 102 |
+
RUN /install_java.sh && rm /install_java.sh
|
| 103 |
+
|
| 104 |
+
# Install JaCoCo for JVM coverage.
|
| 105 |
+
RUN wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.7/org.jacoco.cli-0.8.7-nodeps.jar -O /opt/jacoco-cli.jar && \
|
| 106 |
+
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.7/org.jacoco.agent-0.8.7-runtime.jar -O /opt/jacoco-agent.jar && \
|
| 107 |
+
echo "37df187b76888101ecd745282e9cd1ad4ea508d6 /opt/jacoco-agent.jar" | shasum --check && \
|
| 108 |
+
echo "c1814e7bba5fd8786224b09b43c84fd6156db690 /opt/jacoco-cli.jar" | shasum --check
|
| 109 |
+
|
| 110 |
+
COPY install_javascript.sh /
|
| 111 |
+
RUN /install_javascript.sh && rm /install_javascript.sh
|
| 112 |
+
|
| 113 |
+
# Copy built ruby and ruzzy from builder
|
| 114 |
+
COPY --from=base-ruby /usr/local/rvm /usr/local/rvm
|
| 115 |
+
COPY --from=base-ruby /install/ruzzy /install/ruzzy
|
| 116 |
+
COPY ruzzy /usr/bin/ruzzy
|
| 117 |
+
ENV PATH="$PATH:/usr/local/rvm/rubies/ruby-3.3.1/bin"
|
| 118 |
+
# RubyGems installation directory
|
| 119 |
+
ENV GEM_HOME="$OUT/fuzz-gem"
|
| 120 |
+
ENV GEM_PATH="/install/ruzzy"
|
| 121 |
+
|
| 122 |
+
# Do this last to make developing these files easier/faster due to caching.
|
| 123 |
+
COPY bad_build_check \
|
| 124 |
+
coverage \
|
| 125 |
+
coverage_helper \
|
| 126 |
+
download_corpus \
|
| 127 |
+
jacoco_report_converter.py \
|
| 128 |
+
nyc_report_converter.py \
|
| 129 |
+
rcfilt \
|
| 130 |
+
reproduce \
|
| 131 |
+
run_fuzzer \
|
| 132 |
+
parse_options.py \
|
| 133 |
+
generate_differential_cov_report.py \
|
| 134 |
+
profraw_update.py \
|
| 135 |
+
targets_list \
|
| 136 |
+
test_all.py \
|
| 137 |
+
test_one.py \
|
| 138 |
+
python_coverage_runner_help.py \
|
| 139 |
+
/usr/local/bin/
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/bad_build_check
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -u
|
| 2 |
+
# Copyright 2017 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# A minimal number of runs to test fuzz target with a non-empty input.
|
| 19 |
+
MIN_NUMBER_OF_RUNS=4
|
| 20 |
+
|
| 21 |
+
# The "example" target has 73 with ASan, 65 with UBSan, and 6648 with MSan.
|
| 22 |
+
# Real world targets have greater values (arduinojson: 407, zlib: 664).
|
| 23 |
+
# Mercurial's bdiff_fuzzer has 116 PCs when built with ASan.
|
| 24 |
+
THRESHOLD_FOR_NUMBER_OF_EDGES=100
|
| 25 |
+
|
| 26 |
+
# A fuzz target is supposed to have at least two functions, such as
|
| 27 |
+
# LLVMFuzzerTestOneInput and an API that is being called from there.
|
| 28 |
+
THRESHOLD_FOR_NUMBER_OF_FUNCTIONS=2
|
| 29 |
+
|
| 30 |
+
# Threshold values for different sanitizers used by instrumentation checks.
|
| 31 |
+
ASAN_CALLS_THRESHOLD_FOR_ASAN_BUILD=1000
|
| 32 |
+
ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD=0
|
| 33 |
+
|
| 34 |
+
# The value below can definitely be higher (like 500-1000), but avoid being too
|
| 35 |
+
# agressive here while still evaluating the DFT-based fuzzing approach.
|
| 36 |
+
DFSAN_CALLS_THRESHOLD_FOR_DFSAN_BUILD=100
|
| 37 |
+
DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD=0
|
| 38 |
+
|
| 39 |
+
MSAN_CALLS_THRESHOLD_FOR_MSAN_BUILD=1000
|
| 40 |
+
# Some engines (e.g. honggfuzz) may make a very small number of calls to msan
|
| 41 |
+
# for memory poisoning.
|
| 42 |
+
MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD=3
|
| 43 |
+
|
| 44 |
+
# Usually, a non UBSan build (e.g. ASan) has 165 calls to UBSan runtime. The
|
| 45 |
+
# majority of targets built with UBSan have 200+ UBSan calls, but there are
|
| 46 |
+
# some very small targets that may have < 200 UBSan calls even in a UBSan build.
|
| 47 |
+
# Use the threshold value of 168 (slightly > 165) for UBSan build.
|
| 48 |
+
UBSAN_CALLS_THRESHOLD_FOR_UBSAN_BUILD=168
|
| 49 |
+
|
| 50 |
+
# It would be risky to use the threshold value close to 165 for non UBSan build,
|
| 51 |
+
# as UBSan runtime may change any time and thus we could have different number
|
| 52 |
+
# of calls to UBSan runtime even in ASan build. With that, we use the threshold
|
| 53 |
+
# value of 200 that would detect unnecessary UBSan instrumentation in the vast
|
| 54 |
+
# majority of targets, except of a handful very small ones, which would not be
|
| 55 |
+
# a big concern either way as the overhead for them would not be significant.
|
| 56 |
+
UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD=200
|
| 57 |
+
|
| 58 |
+
# ASan builds on i386 generally have about 250 UBSan runtime calls.
|
| 59 |
+
if [[ $ARCHITECTURE == 'i386' ]]
|
| 60 |
+
then
|
| 61 |
+
UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD=280
|
| 62 |
+
fi
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# Verify that the given fuzz target is correctly built to run with a particular
|
| 66 |
+
# engine.
|
| 67 |
+
function check_engine {
|
| 68 |
+
local FUZZER=$1
|
| 69 |
+
local FUZZER_NAME=$(basename $FUZZER)
|
| 70 |
+
local FUZZER_OUTPUT="/tmp/$FUZZER_NAME.output"
|
| 71 |
+
local CHECK_FAILED=0
|
| 72 |
+
|
| 73 |
+
if [[ "$FUZZING_ENGINE" == libfuzzer ]]; then
|
| 74 |
+
# Store fuzz target's output into a temp file to be used for further checks.
|
| 75 |
+
$FUZZER -seed=1337 -runs=$MIN_NUMBER_OF_RUNS &>$FUZZER_OUTPUT
|
| 76 |
+
CHECK_FAILED=$(egrep "ERROR: no interesting inputs were found. Is the code instrumented" -c $FUZZER_OUTPUT)
|
| 77 |
+
if (( $CHECK_FAILED > 0 )); then
|
| 78 |
+
echo "BAD BUILD: $FUZZER does not seem to have coverage instrumentation."
|
| 79 |
+
cat $FUZZER_OUTPUT
|
| 80 |
+
# Bail out as the further check does not make any sense, there are 0 PCs.
|
| 81 |
+
return 1
|
| 82 |
+
fi
|
| 83 |
+
|
| 84 |
+
local NUMBER_OF_EDGES=$(grep -Po "INFO: Loaded [[:digit:]]+ module.*\(.*(counters|guards)\):[[:space:]]+\K[[:digit:]]+" $FUZZER_OUTPUT)
|
| 85 |
+
|
| 86 |
+
# If a fuzz target fails to start, grep won't find anything, so bail out early to let check_startup_crash deal with it.
|
| 87 |
+
[[ -z "$NUMBER_OF_EDGES" ]] && return
|
| 88 |
+
|
| 89 |
+
if (( $NUMBER_OF_EDGES < $THRESHOLD_FOR_NUMBER_OF_EDGES )); then
|
| 90 |
+
echo "BAD BUILD: $FUZZER seems to have only partial coverage instrumentation."
|
| 91 |
+
fi
|
| 92 |
+
elif [[ "$FUZZING_ENGINE" == afl ]]; then
|
| 93 |
+
AFL_FORKSRV_INIT_TMOUT=30000 AFL_NO_UI=1 SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 35s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 94 |
+
CHECK_PASSED=$(egrep "All set and ready to roll" -c $FUZZER_OUTPUT)
|
| 95 |
+
if (( $CHECK_PASSED == 0 )); then
|
| 96 |
+
echo "BAD BUILD: fuzzing $FUZZER with afl-fuzz failed."
|
| 97 |
+
cat $FUZZER_OUTPUT
|
| 98 |
+
return 1
|
| 99 |
+
fi
|
| 100 |
+
elif [[ "$FUZZING_ENGINE" == honggfuzz ]]; then
|
| 101 |
+
SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 20s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 102 |
+
CHECK_PASSED=$(egrep "^Sz:[0-9]+ Tm:[0-9]+" -c $FUZZER_OUTPUT)
|
| 103 |
+
if (( $CHECK_PASSED == 0 )); then
|
| 104 |
+
echo "BAD BUILD: fuzzing $FUZZER with honggfuzz failed."
|
| 105 |
+
cat $FUZZER_OUTPUT
|
| 106 |
+
return 1
|
| 107 |
+
fi
|
| 108 |
+
elif [[ "$FUZZING_ENGINE" == dataflow ]]; then
|
| 109 |
+
$FUZZER &> $FUZZER_OUTPUT
|
| 110 |
+
local NUMBER_OF_FUNCTIONS=$(grep -Po "INFO:\s+\K[[:digit:]]+(?=\s+instrumented function.*)" $FUZZER_OUTPUT)
|
| 111 |
+
[[ -z "$NUMBER_OF_FUNCTIONS" ]] && NUMBER_OF_FUNCTIONS=0
|
| 112 |
+
if (( $NUMBER_OF_FUNCTIONS < $THRESHOLD_FOR_NUMBER_OF_FUNCTIONS )); then
|
| 113 |
+
echo "BAD BUILD: $FUZZER does not seem to be properly built in 'dataflow' config."
|
| 114 |
+
cat $FUZZER_OUTPUT
|
| 115 |
+
return 1
|
| 116 |
+
fi
|
| 117 |
+
elif [[ "$FUZZING_ENGINE" == centipede \
|
| 118 |
+
&& ("${HELPER:-}" == True || "$SANITIZER" == none ) ]]; then
|
| 119 |
+
# Performs run test on unsanitized binaries with auxiliary sanitized
|
| 120 |
+
# binaries if they are built with helper.py.
|
| 121 |
+
# Performs run test on unsanitized binaries without auxiliary sanitized
|
| 122 |
+
# binaries if they are from trial build and production build.
|
| 123 |
+
# TODO(Dongge): Support run test with sanitized binaries for trial and
|
| 124 |
+
# production build.
|
| 125 |
+
SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 20s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 126 |
+
CHECK_PASSED=$(egrep "\[S0.0] begin-fuzz: ft: 0 corp: 0/0" -c $FUZZER_OUTPUT)
|
| 127 |
+
if (( $CHECK_PASSED == 0 )); then
|
| 128 |
+
echo "BAD BUILD: fuzzing $FUZZER with centipede failed."
|
| 129 |
+
cat $FUZZER_OUTPUT
|
| 130 |
+
return 1
|
| 131 |
+
fi
|
| 132 |
+
fi
|
| 133 |
+
|
| 134 |
+
return 0
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
# Verify that the given fuzz target has been built properly and works.
|
| 138 |
+
function check_startup_crash {
|
| 139 |
+
local FUZZER=$1
|
| 140 |
+
local FUZZER_NAME=$(basename $FUZZER)
|
| 141 |
+
local FUZZER_OUTPUT="/tmp/$FUZZER_NAME.output"
|
| 142 |
+
local CHECK_PASSED=0
|
| 143 |
+
|
| 144 |
+
if [[ "$FUZZING_ENGINE" = libfuzzer ]]; then
|
| 145 |
+
# Skip seed corpus as there is another explicit check that uses seed corpora.
|
| 146 |
+
SKIP_SEED_CORPUS=1 run_fuzzer $FUZZER_NAME -seed=1337 -runs=$MIN_NUMBER_OF_RUNS &>$FUZZER_OUTPUT
|
| 147 |
+
CHECK_PASSED=$(egrep "Done $MIN_NUMBER_OF_RUNS runs" -c $FUZZER_OUTPUT)
|
| 148 |
+
elif [[ "$FUZZING_ENGINE" = afl ]]; then
|
| 149 |
+
AFL_FORKSRV_INIT_TMOUT=30000 AFL_NO_UI=1 SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 35s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 150 |
+
if [ $(egrep "target binary (crashed|terminated)" -c $FUZZER_OUTPUT) -eq 0 ]; then
|
| 151 |
+
CHECK_PASSED=1
|
| 152 |
+
fi
|
| 153 |
+
elif [[ "$FUZZING_ENGINE" = dataflow ]]; then
|
| 154 |
+
# TODO(https://github.com/google/oss-fuzz/issues/1632): add check for
|
| 155 |
+
# binaries compiled with dataflow engine when the interface becomes stable.
|
| 156 |
+
CHECK_PASSED=1
|
| 157 |
+
else
|
| 158 |
+
# TODO: add checks for another fuzzing engines if possible.
|
| 159 |
+
CHECK_PASSED=1
|
| 160 |
+
fi
|
| 161 |
+
|
| 162 |
+
if [ "$CHECK_PASSED" -eq "0" ]; then
|
| 163 |
+
echo "BAD BUILD: $FUZZER seems to have either startup crash or exit:"
|
| 164 |
+
cat $FUZZER_OUTPUT
|
| 165 |
+
return 1
|
| 166 |
+
fi
|
| 167 |
+
|
| 168 |
+
return 0
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
# Mixed sanitizers check for ASan build.
|
| 172 |
+
function check_asan_build {
|
| 173 |
+
local FUZZER=$1
|
| 174 |
+
local ASAN_CALLS=$2
|
| 175 |
+
local DFSAN_CALLS=$3
|
| 176 |
+
local MSAN_CALLS=$4
|
| 177 |
+
local UBSAN_CALLS=$5
|
| 178 |
+
|
| 179 |
+
# Perform all the checks for more detailed error message.
|
| 180 |
+
if (( $ASAN_CALLS < $ASAN_CALLS_THRESHOLD_FOR_ASAN_BUILD )); then
|
| 181 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with ASan."
|
| 182 |
+
return 1
|
| 183 |
+
fi
|
| 184 |
+
|
| 185 |
+
if (( $DFSAN_CALLS > $DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD )); then
|
| 186 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with DFSan."
|
| 187 |
+
return 1
|
| 188 |
+
fi
|
| 189 |
+
|
| 190 |
+
if (( $MSAN_CALLS > $MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD )); then
|
| 191 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with MSan."
|
| 192 |
+
return 1
|
| 193 |
+
fi
|
| 194 |
+
|
| 195 |
+
if (( $UBSAN_CALLS > $UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD )); then
|
| 196 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with UBSan."
|
| 197 |
+
return 1
|
| 198 |
+
fi
|
| 199 |
+
|
| 200 |
+
return 0
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
# Mixed sanitizers check for DFSan build.
|
| 204 |
+
function check_dfsan_build {
|
| 205 |
+
local FUZZER=$1
|
| 206 |
+
local ASAN_CALLS=$2
|
| 207 |
+
local DFSAN_CALLS=$3
|
| 208 |
+
local MSAN_CALLS=$4
|
| 209 |
+
local UBSAN_CALLS=$5
|
| 210 |
+
|
| 211 |
+
# Perform all the checks for more detailed error message.
|
| 212 |
+
if (( $ASAN_CALLS > $ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD )); then
|
| 213 |
+
echo "BAD BUILD: DFSan build of $FUZZER seems to be compiled with ASan."
|
| 214 |
+
return 1
|
| 215 |
+
fi
|
| 216 |
+
|
| 217 |
+
if (( $DFSAN_CALLS < $DFSAN_CALLS_THRESHOLD_FOR_DFSAN_BUILD )); then
|
| 218 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with DFSan."
|
| 219 |
+
return 1
|
| 220 |
+
fi
|
| 221 |
+
|
| 222 |
+
if (( $MSAN_CALLS > $MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD )); then
|
| 223 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with MSan."
|
| 224 |
+
return 1
|
| 225 |
+
fi
|
| 226 |
+
|
| 227 |
+
if (( $UBSAN_CALLS > $UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD )); then
|
| 228 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with UBSan."
|
| 229 |
+
return 1
|
| 230 |
+
fi
|
| 231 |
+
|
| 232 |
+
return 0
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
# Mixed sanitizers check for MSan build.
|
| 237 |
+
function check_msan_build {
|
| 238 |
+
local FUZZER=$1
|
| 239 |
+
local ASAN_CALLS=$2
|
| 240 |
+
local DFSAN_CALLS=$3
|
| 241 |
+
local MSAN_CALLS=$4
|
| 242 |
+
local UBSAN_CALLS=$5
|
| 243 |
+
|
| 244 |
+
# Perform all the checks for more detailed error message.
|
| 245 |
+
if (( $ASAN_CALLS > $ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD )); then
|
| 246 |
+
echo "BAD BUILD: MSan build of $FUZZER seems to be compiled with ASan."
|
| 247 |
+
return 1
|
| 248 |
+
fi
|
| 249 |
+
|
| 250 |
+
if (( $DFSAN_CALLS > $DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD )); then
|
| 251 |
+
echo "BAD BUILD: MSan build of $FUZZER seems to be compiled with DFSan."
|
| 252 |
+
return 1
|
| 253 |
+
fi
|
| 254 |
+
|
| 255 |
+
if (( $MSAN_CALLS < $MSAN_CALLS_THRESHOLD_FOR_MSAN_BUILD )); then
|
| 256 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with MSan."
|
| 257 |
+
return 1
|
| 258 |
+
fi
|
| 259 |
+
|
| 260 |
+
if (( $UBSAN_CALLS > $UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD )); then
|
| 261 |
+
echo "BAD BUILD: MSan build of $FUZZER seems to be compiled with UBSan."
|
| 262 |
+
return 1
|
| 263 |
+
fi
|
| 264 |
+
|
| 265 |
+
return 0
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
# Mixed sanitizers check for UBSan build.
|
| 269 |
+
function check_ubsan_build {
|
| 270 |
+
local FUZZER=$1
|
| 271 |
+
local ASAN_CALLS=$2
|
| 272 |
+
local DFSAN_CALLS=$3
|
| 273 |
+
local MSAN_CALLS=$4
|
| 274 |
+
local UBSAN_CALLS=$5
|
| 275 |
+
|
| 276 |
+
if [[ "$FUZZING_ENGINE" != libfuzzer ]]; then
|
| 277 |
+
# Ignore UBSan checks for fuzzing engines other than libFuzzer because:
|
| 278 |
+
# A) we (probably) are not going to use those with UBSan
|
| 279 |
+
# B) such builds show indistinguishable number of calls to UBSan
|
| 280 |
+
return 0
|
| 281 |
+
fi
|
| 282 |
+
|
| 283 |
+
# Perform all the checks for more detailed error message.
|
| 284 |
+
if (( $ASAN_CALLS > $ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD )); then
|
| 285 |
+
echo "BAD BUILD: UBSan build of $FUZZER seems to be compiled with ASan."
|
| 286 |
+
return 1
|
| 287 |
+
fi
|
| 288 |
+
|
| 289 |
+
if (( $DFSAN_CALLS > $DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD )); then
|
| 290 |
+
echo "BAD BUILD: UBSan build of $FUZZER seems to be compiled with DFSan."
|
| 291 |
+
return 1
|
| 292 |
+
fi
|
| 293 |
+
|
| 294 |
+
if (( $MSAN_CALLS > $MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD )); then
|
| 295 |
+
echo "BAD BUILD: UBSan build of $FUZZER seems to be compiled with MSan."
|
| 296 |
+
return 1
|
| 297 |
+
fi
|
| 298 |
+
|
| 299 |
+
if (( $UBSAN_CALLS < $UBSAN_CALLS_THRESHOLD_FOR_UBSAN_BUILD )); then
|
| 300 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with UBSan."
|
| 301 |
+
return 1
|
| 302 |
+
fi
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
# Verify that the given fuzz target is compiled with correct sanitizer.
|
| 306 |
+
function check_mixed_sanitizers {
|
| 307 |
+
local FUZZER=$1
|
| 308 |
+
local result=0
|
| 309 |
+
local CALL_INSN=
|
| 310 |
+
|
| 311 |
+
if [ "${FUZZING_LANGUAGE:-}" = "jvm" ]; then
|
| 312 |
+
# Sanitizer runtime is linked into the Jazzer driver, so this check does not
|
| 313 |
+
# apply.
|
| 314 |
+
return 0
|
| 315 |
+
fi
|
| 316 |
+
|
| 317 |
+
if [ "${FUZZING_LANGUAGE:-}" = "javascript" ]; then
|
| 318 |
+
# Jazzer.js currently does not support using sanitizers with native Node.js addons.
|
| 319 |
+
# This is not relevant anyways since supporting this will be done by preloading
|
| 320 |
+
# the sanitizers in the wrapper script starting Jazzer.js.
|
| 321 |
+
return 0
|
| 322 |
+
fi
|
| 323 |
+
|
| 324 |
+
if [ "${FUZZING_LANGUAGE:-}" = "python" ]; then
|
| 325 |
+
# Sanitizer runtime is loaded via LD_PRELOAD, so this check does not apply.
|
| 326 |
+
return 0
|
| 327 |
+
fi
|
| 328 |
+
|
| 329 |
+
# For fuzztest fuzzers point to the binary instead of launcher script.
|
| 330 |
+
if [[ $FUZZER == *"@"* ]]; then
|
| 331 |
+
FUZZER=(${FUZZER//@/ }[0])
|
| 332 |
+
fi
|
| 333 |
+
|
| 334 |
+
CALL_INSN=
|
| 335 |
+
if [[ $ARCHITECTURE == "x86_64" ]]
|
| 336 |
+
then
|
| 337 |
+
CALL_INSN="callq?\s+[0-9a-f]+\s+<"
|
| 338 |
+
elif [[ $ARCHITECTURE == "i386" ]]
|
| 339 |
+
then
|
| 340 |
+
CALL_INSN="call\s+[0-9a-f]+\s+<"
|
| 341 |
+
elif [[ $ARCHITECTURE == "aarch64" ]]
|
| 342 |
+
then
|
| 343 |
+
CALL_INSN="bl\s+[0-9a-f]+\s+<"
|
| 344 |
+
else
|
| 345 |
+
echo "UNSUPPORTED ARCHITECTURE"
|
| 346 |
+
exit 1
|
| 347 |
+
fi
|
| 348 |
+
local ASAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__asan" -c)
|
| 349 |
+
local DFSAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__dfsan" -c)
|
| 350 |
+
local MSAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__msan" -c)
|
| 351 |
+
local UBSAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__ubsan" -c)
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
if [[ "$SANITIZER" = address ]]; then
|
| 355 |
+
check_asan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 356 |
+
result=$?
|
| 357 |
+
elif [[ "$SANITIZER" = dataflow ]]; then
|
| 358 |
+
check_dfsan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 359 |
+
result=$?
|
| 360 |
+
elif [[ "$SANITIZER" = memory ]]; then
|
| 361 |
+
check_msan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 362 |
+
result=$?
|
| 363 |
+
elif [[ "$SANITIZER" = undefined ]]; then
|
| 364 |
+
check_ubsan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 365 |
+
result=$?
|
| 366 |
+
elif [[ "$SANITIZER" = thread ]]; then
|
| 367 |
+
# TODO(metzman): Implement this.
|
| 368 |
+
result=0
|
| 369 |
+
fi
|
| 370 |
+
|
| 371 |
+
return $result
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
# Verify that the given fuzz target doesn't crash on the seed corpus.
|
| 375 |
+
function check_seed_corpus {
|
| 376 |
+
local FUZZER=$1
|
| 377 |
+
local FUZZER_NAME="$(basename $FUZZER)"
|
| 378 |
+
local FUZZER_OUTPUT="/tmp/$FUZZER_NAME.output"
|
| 379 |
+
|
| 380 |
+
if [[ "$FUZZING_ENGINE" != libfuzzer ]]; then
|
| 381 |
+
return 0
|
| 382 |
+
fi
|
| 383 |
+
|
| 384 |
+
# Set up common fuzzing arguments, otherwise "run_fuzzer" errors out.
|
| 385 |
+
if [ -z "$FUZZER_ARGS" ]; then
|
| 386 |
+
export FUZZER_ARGS="-rss_limit_mb=2560 -timeout=25"
|
| 387 |
+
fi
|
| 388 |
+
|
| 389 |
+
bash -c "run_fuzzer $FUZZER_NAME -runs=0" &> $FUZZER_OUTPUT
|
| 390 |
+
|
| 391 |
+
# Don't output anything if fuzz target hasn't crashed.
|
| 392 |
+
if [ $? -ne 0 ]; then
|
| 393 |
+
echo "BAD BUILD: $FUZZER has a crashing input in its seed corpus:"
|
| 394 |
+
cat $FUZZER_OUTPUT
|
| 395 |
+
return 1
|
| 396 |
+
fi
|
| 397 |
+
|
| 398 |
+
return 0
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
function check_architecture {
|
| 402 |
+
local FUZZER=$1
|
| 403 |
+
local FUZZER_NAME=$(basename $FUZZER)
|
| 404 |
+
|
| 405 |
+
if [ "${FUZZING_LANGUAGE:-}" = "jvm" ]; then
|
| 406 |
+
# The native dependencies of a JVM project are not packaged, but loaded
|
| 407 |
+
# dynamically at runtime and thus cannot be checked here.
|
| 408 |
+
return 0;
|
| 409 |
+
fi
|
| 410 |
+
|
| 411 |
+
if [ "${FUZZING_LANGUAGE:-}" = "javascript" ]; then
|
| 412 |
+
# Jazzer.js fuzzers are wrapper scripts that start the fuzz target with
|
| 413 |
+
# the Jazzer.js CLI.
|
| 414 |
+
return 0;
|
| 415 |
+
fi
|
| 416 |
+
|
| 417 |
+
if [ "${FUZZING_LANGUAGE:-}" = "python" ]; then
|
| 418 |
+
FUZZER=${FUZZER}.pkg
|
| 419 |
+
fi
|
| 420 |
+
|
| 421 |
+
# For fuzztest fuzzers point to the binary instead of launcher script.
|
| 422 |
+
if [[ $FUZZER == *"@"* ]]; then
|
| 423 |
+
FUZZER=(${FUZZER//@/ }[0])
|
| 424 |
+
fi
|
| 425 |
+
|
| 426 |
+
FILE_OUTPUT=$(file $FUZZER)
|
| 427 |
+
if [[ $ARCHITECTURE == "x86_64" ]]
|
| 428 |
+
then
|
| 429 |
+
echo $FILE_OUTPUT | grep "x86-64" > /dev/null
|
| 430 |
+
elif [[ $ARCHITECTURE == "i386" ]]
|
| 431 |
+
then
|
| 432 |
+
echo $FILE_OUTPUT | grep "80386" > /dev/null
|
| 433 |
+
elif [[ $ARCHITECTURE == "aarch64" ]]
|
| 434 |
+
then
|
| 435 |
+
echo $FILE_OUTPUT | grep "aarch64" > /dev/null
|
| 436 |
+
else
|
| 437 |
+
echo "UNSUPPORTED ARCHITECTURE"
|
| 438 |
+
return 1
|
| 439 |
+
fi
|
| 440 |
+
result=$?
|
| 441 |
+
if [[ $result != 0 ]]
|
| 442 |
+
then
|
| 443 |
+
echo "BAD BUILD $FUZZER is not built for architecture: $ARCHITECTURE"
|
| 444 |
+
echo "file command output: $FILE_OUTPUT"
|
| 445 |
+
echo "check_mixed_sanitizers test will fail."
|
| 446 |
+
fi
|
| 447 |
+
return $result
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
function main {
|
| 451 |
+
local FUZZER=$1
|
| 452 |
+
local AUXILIARY_FUZZER=${2:-}
|
| 453 |
+
local checks_failed=0
|
| 454 |
+
local result=0
|
| 455 |
+
|
| 456 |
+
export RUN_FUZZER_MODE="batch"
|
| 457 |
+
check_engine $FUZZER
|
| 458 |
+
result=$?
|
| 459 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 460 |
+
|
| 461 |
+
check_architecture $FUZZER
|
| 462 |
+
result=$?
|
| 463 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 464 |
+
|
| 465 |
+
if [[ "$FUZZING_ENGINE" == centipede \
|
| 466 |
+
&& "$SANITIZER" != none && "${HELPER:-}" == True ]]; then
|
| 467 |
+
check_mixed_sanitizers $AUXILIARY_FUZZER
|
| 468 |
+
else
|
| 469 |
+
check_mixed_sanitizers $FUZZER
|
| 470 |
+
fi
|
| 471 |
+
result=$?
|
| 472 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 473 |
+
|
| 474 |
+
check_startup_crash $FUZZER
|
| 475 |
+
result=$?
|
| 476 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 477 |
+
|
| 478 |
+
# TODO: re-enable after introducing bug auto-filing for bad builds.
|
| 479 |
+
# check_seed_corpus $FUZZER
|
| 480 |
+
return $checks_failed
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
if [ $# -ne 1 -a $# -ne 2 ]; then
|
| 485 |
+
echo "Usage: $0 <fuzz_target_binary> [<auxiliary_binary>]"
|
| 486 |
+
exit 1
|
| 487 |
+
fi
|
| 488 |
+
|
| 489 |
+
# Fuzz target path.
|
| 490 |
+
FUZZER=$1
|
| 491 |
+
AUXILIARY_FUZZER=${2:-}
|
| 492 |
+
|
| 493 |
+
main $FUZZER $AUXILIARY_FUZZER
|
| 494 |
+
exit $?
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/coverage_helper
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -u
|
| 2 |
+
# Copyright 2018 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
python3 $CODE_COVERAGE_SRC/coverage_utils.py $@
|
local-test-tika-full-01-vuln_1/fuzz-tooling/infra/base-images/base-runner/install_javascript.sh
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2023 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
# see installation instructions: https://github.com/nodesource/distributions#available-architectures
|
| 18 |
+
apt-get update
|
| 19 |
+
apt-get install -y ca-certificates curl gnupg
|
| 20 |
+
mkdir -p /etc/apt/keyrings
|
| 21 |
+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
| 22 |
+
|
| 23 |
+
NODE_MAJOR=20
|
| 24 |
+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
|
| 25 |
+
|
| 26 |
+
apt-get update
|
| 27 |
+
apt-get install nodejs -y
|
| 28 |
+
|
| 29 |
+
# Install latest versions of nyc for source-based coverage reporting
|
| 30 |
+
npm install --global nyc
|