Kitxuuu commited on
Commit
5cdcc87
·
verified ·
1 Parent(s): 6f0d815

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc +0 -0
  2. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/base-images/README.md +6 -0
  3. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/base_runner_utils.py +33 -0
  4. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/build-images.sh +34 -0
  5. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/cifuzz_combined_entrypoint.py +40 -0
  6. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/clusterfuzz_deployment_test.py +268 -0
  7. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore_utils.py +48 -0
  8. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/requirements.txt +4 -0
  9. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/uploader/Dockerfile +7 -0
  10. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts +80 -0
  11. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdDispatcherGenerateClusterfuzzLite.ts +38 -0
  12. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdEndToEndCoverage.ts +192 -0
  13. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdRedo.ts +35 -0
  14. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts +167 -0
  15. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFI.ts +24 -0
  16. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFuzzer.ts +83 -0
  17. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupCIFuzz.ts +87 -0
  18. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdTemplate.ts +357 -0
  19. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzerCFLite.ts +89 -0
  20. local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/extension.ts +227 -0
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc ADDED
Binary file (802 Bytes). View file
 
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/base-images/README.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Building all infra images:
2
+
3
+ ```bash
4
+ # run from project root
5
+ infra/base-images/all.sh
6
+ ```
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/base_runner_utils.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+ """Utilities for scripts from ghcr.io/aixcc-finals/base-runner."""
15
+
16
+ import os
17
+
18
+ import config_utils
19
+
20
+
21
+ def get_env(config, workspace):
22
+ """Returns a dictionary containing the current environment with additional env
23
+ vars set to values needed to run a fuzzer."""
24
+ env = os.environ.copy()
25
+ env['SANITIZER'] = config.sanitizer
26
+ env['FUZZING_LANGUAGE'] = config.language
27
+ env['OUT'] = workspace.out
28
+ env['CIFUZZ'] = 'True'
29
+ env['FUZZING_ENGINE'] = config_utils.DEFAULT_ENGINE
30
+ env['ARCHITECTURE'] = config.architecture
31
+ # Do this so we don't fail in tests.
32
+ env['FUZZER_ARGS'] = '-rss_limit_mb=2560 -timeout=25'
33
+ return env
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/build-images.sh ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Script for building the docker images for cifuzz.
17
+
18
+ CIFUZZ_DIR=$(dirname "$0")
19
+ CIFUZZ_DIR=$(realpath $CIFUZZ_DIR)
20
+ INFRA_DIR=$(realpath $CIFUZZ_DIR/..)
21
+ OSS_FUZZ_ROOT=$(realpath $INFRA_DIR/..)
22
+
23
+ # Build cifuzz-base.
24
+ docker build --tag ghcr.io/aixcc-finals/cifuzz-base --file $CIFUZZ_DIR/cifuzz-base/Dockerfile $OSS_FUZZ_ROOT
25
+
26
+ # Build run-fuzzers and build-fuzzers images.
27
+ docker build \
28
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-build-fuzzers-test:v1 \
29
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-build-fuzzers:v1 \
30
+ --file $INFRA_DIR/build_fuzzers.Dockerfile $INFRA_DIR
31
+ docker build \
32
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-run-fuzzers:v1 \
33
+ --tag ghcr.io/aixcc-finals/clusterfuzzlite-run-fuzzers-test:v1 \
34
+ --file $INFRA_DIR/run_fuzzers.Dockerfile $INFRA_DIR
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/cifuzz_combined_entrypoint.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+ """Builds fuzzers and runs fuzzers. Entrypoint used for external users"""
15
+ import logging
16
+ import sys
17
+
18
+ import build_fuzzers_entrypoint
19
+ import run_fuzzers_entrypoint
20
+
21
+
22
+ def main():
23
+ """Builds and runs fuzzers for CI tools.
24
+
25
+ NOTE: Any crash report will be in the filepath: $WORKSPACE/out/testcase
26
+ This can be used with GitHub's upload-artifact action to surface the logs.
27
+
28
+ Required environment variables:
29
+ Returns:
30
+ 0 on success or 1 on failure.
31
+ """
32
+ logging.debug("Using cifuzz_combined_entrypoint.")
33
+ result = build_fuzzers_entrypoint.build_fuzzers_entrypoint()
34
+ if result != 0:
35
+ return result
36
+ return run_fuzzers_entrypoint.run_fuzzers_entrypoint()
37
+
38
+
39
+ if __name__ == '__main__':
40
+ sys.exit(main())
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/clusterfuzz_deployment_test.py ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+ """Tests for clusterfuzz_deployment.py"""
15
+
16
+ import os
17
+ import unittest
18
+ from unittest import mock
19
+
20
+ import parameterized
21
+ from pyfakefs import fake_filesystem_unittest
22
+
23
+ import clusterfuzz_deployment
24
+ import config_utils
25
+ import test_helpers
26
+ import workspace_utils
27
+
28
+ # NOTE: This integration test relies on
29
+ # https://github.com/google/oss-fuzz/tree/master/projects/example project.
30
+ EXAMPLE_PROJECT = 'example'
31
+
32
+ # An example fuzzer that triggers an error.
33
+ EXAMPLE_FUZZER = 'example_crash_fuzzer'
34
+
35
+ WORKSPACE = '/workspace'
36
+ EXPECTED_LATEST_BUILD_PATH = os.path.join(WORKSPACE, 'cifuzz-prev-build')
37
+
38
+ # pylint: disable=unused-argument
39
+
40
+
41
+ def _create_config(**kwargs):
42
+ """Creates a config object and then sets every attribute that is a key in
43
+ |kwargs| to the corresponding value. Asserts that each key in |kwargs| is an
44
+ attribute of Config."""
45
+ defaults = {
46
+ 'cfl_platform': 'github',
47
+ 'oss_fuzz_project_name': EXAMPLE_PROJECT,
48
+ 'workspace': WORKSPACE,
49
+ }
50
+ for default_key, default_value in defaults.items():
51
+ if default_key not in kwargs:
52
+ kwargs[default_key] = default_value
53
+
54
+ return test_helpers.create_run_config(**kwargs)
55
+
56
+
57
+ def _create_deployment(**kwargs):
58
+ config = _create_config(**kwargs)
59
+ workspace = workspace_utils.Workspace(config)
60
+ return clusterfuzz_deployment.get_clusterfuzz_deployment(config, workspace)
61
+
62
+
63
+ class OSSFuzzTest(fake_filesystem_unittest.TestCase):
64
+ """Tests OSSFuzz."""
65
+
66
+ def setUp(self):
67
+ self.setUpPyfakefs()
68
+ self.deployment = _create_deployment()
69
+ self.corpus_dir = os.path.join(self.deployment.workspace.corpora,
70
+ EXAMPLE_FUZZER)
71
+
72
+ @mock.patch('http_utils.download_and_unpack_zip', return_value=True)
73
+ def test_download_corpus(self, mock_download_and_unpack_zip):
74
+ """Tests that we can download a corpus for a valid project."""
75
+ self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
76
+ expected_url = ('https://storage.googleapis.com/example-backup.'
77
+ 'clusterfuzz-external.appspot.com/corpus/libFuzzer/'
78
+ 'example_crash_fuzzer/public.zip')
79
+ call_args, _ = mock_download_and_unpack_zip.call_args
80
+ self.assertEqual(call_args, (expected_url, self.corpus_dir))
81
+ self.assertTrue(os.path.exists(self.corpus_dir))
82
+
83
+ @mock.patch('http_utils.download_and_unpack_zip', return_value=False)
84
+ def test_download_corpus_fail(self, _):
85
+ """Tests that when downloading fails, an empty corpus directory is still
86
+ returned."""
87
+ self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
88
+ self.assertEqual(os.listdir(self.corpus_dir), [])
89
+
90
+ def test_get_latest_build_name(self):
91
+ """Tests that the latest build name can be retrieved from GCS."""
92
+ latest_build_name = self.deployment.get_latest_build_name()
93
+ self.assertTrue(latest_build_name.endswith('.zip'))
94
+ self.assertTrue('address' in latest_build_name)
95
+
96
+ @parameterized.parameterized.expand([
97
+ ('upload_build', ('commit',),
98
+ 'Not uploading latest build because on OSS-Fuzz.'),
99
+ ('upload_corpus', ('target', 'corpus-dir'),
100
+ 'Not uploading corpus because on OSS-Fuzz.'),
101
+ ('upload_crashes', tuple(), 'Not uploading crashes because on OSS-Fuzz.'),
102
+ ])
103
+ def test_noop_methods(self, method, method_args, expected_message):
104
+ """Tests that certain methods are noops for OSS-Fuzz."""
105
+ with mock.patch('logging.info') as mock_info:
106
+ method = getattr(self.deployment, method)
107
+ self.assertIsNone(method(*method_args))
108
+ mock_info.assert_called_with(expected_message)
109
+
110
+ @mock.patch('http_utils.download_and_unpack_zip', return_value=True)
111
+ def test_download_latest_build(self, mock_download_and_unpack_zip):
112
+ """Tests that downloading the latest build works as intended under normal
113
+ circumstances."""
114
+ self.assertEqual(self.deployment.download_latest_build(),
115
+ EXPECTED_LATEST_BUILD_PATH)
116
+ expected_url = ('https://storage.googleapis.com/clusterfuzz-builds/example/'
117
+ 'example-address-202008030600.zip')
118
+ mock_download_and_unpack_zip.assert_called_with(expected_url,
119
+ EXPECTED_LATEST_BUILD_PATH)
120
+
121
+ @mock.patch('http_utils.download_and_unpack_zip', return_value=False)
122
+ def test_download_latest_build_fail(self, _):
123
+ """Tests that download_latest_build returns None when it fails to download a
124
+ build."""
125
+ self.assertIsNone(self.deployment.download_latest_build())
126
+
127
+
128
+ class ClusterFuzzLiteTest(fake_filesystem_unittest.TestCase):
129
+ """Tests for ClusterFuzzLite."""
130
+
131
+ def setUp(self):
132
+ self.setUpPyfakefs()
133
+ self.deployment = _create_deployment(mode='batch',
134
+ oss_fuzz_project_name='',
135
+ cloud_bucket='gs://bucket')
136
+ self.corpus_dir = os.path.join(self.deployment.workspace.corpora,
137
+ EXAMPLE_FUZZER)
138
+
139
+ @mock.patch('filestore.github_actions.GithubActionsFilestore.download_corpus',
140
+ return_value=True)
141
+ def test_download_corpus(self, mock_download_corpus):
142
+ """Tests that download_corpus works for a valid project."""
143
+ self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
144
+ mock_download_corpus.assert_called_with('example_crash_fuzzer',
145
+ self.corpus_dir)
146
+ self.assertTrue(os.path.exists(self.corpus_dir))
147
+
148
+ @mock.patch('filestore.github_actions.GithubActionsFilestore.download_corpus',
149
+ side_effect=Exception)
150
+ def test_download_corpus_fail(self, _):
151
+ """Tests that when downloading fails, an empty corpus directory is still
152
+ returned."""
153
+ self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
154
+ self.assertEqual(os.listdir(self.corpus_dir), [])
155
+
156
+ @mock.patch('filestore.github_actions.GithubActionsFilestore.download_build',
157
+ side_effect=[False, True])
158
+ @mock.patch('repo_manager.RepoManager.get_commit_list',
159
+ return_value=['commit1', 'commit2'])
160
+ @mock.patch('continuous_integration.GithubCiMixin.repo_dir',
161
+ return_value='/path/to/repo')
162
+ def test_download_latest_build(self, mock_repo_dir, mock_get_commit_list,
163
+ mock_download_build):
164
+ """Tests that downloading the latest build works as intended under normal
165
+ circumstances."""
166
+ self.assertEqual(self.deployment.download_latest_build(),
167
+ EXPECTED_LATEST_BUILD_PATH)
168
+ expected_artifact_name = 'address-commit2'
169
+ mock_download_build.assert_called_with(expected_artifact_name,
170
+ EXPECTED_LATEST_BUILD_PATH)
171
+
172
+ @mock.patch('filestore.github_actions.GithubActionsFilestore.download_build',
173
+ side_effect=Exception)
174
+ @mock.patch('repo_manager.RepoManager.get_commit_list',
175
+ return_value=['commit1', 'commit2'])
176
+ @mock.patch('continuous_integration.GithubCiMixin.repo_dir',
177
+ return_value='/path/to/repo')
178
+ def test_download_latest_build_fail(self, mock_repo_dir, mock_get_commit_list,
179
+ _):
180
+ """Tests that download_latest_build returns None when it fails to download a
181
+ build."""
182
+ self.assertIsNone(self.deployment.download_latest_build())
183
+
184
+ @mock.patch('filestore.github_actions.GithubActionsFilestore.upload_build')
185
+ def test_upload_build(self, mock_upload_build):
186
+ """Tests that upload_build works as intended."""
187
+ self.deployment.upload_build('commit')
188
+ mock_upload_build.assert_called_with('address-commit',
189
+ '/workspace/build-out')
190
+
191
+
192
+ class NoClusterFuzzDeploymentTest(fake_filesystem_unittest.TestCase):
193
+ """Tests for NoClusterFuzzDeployment."""
194
+
195
+ def setUp(self):
196
+ self.setUpPyfakefs()
197
+ config = test_helpers.create_run_config(workspace=WORKSPACE,
198
+ cfl_platform='other',
199
+ filestore='no_filestore',
200
+ no_clusterfuzz_deployment=True)
201
+ workspace = workspace_utils.Workspace(config)
202
+ self.deployment = clusterfuzz_deployment.get_clusterfuzz_deployment(
203
+ config, workspace)
204
+
205
+ self.corpus_dir = os.path.join(workspace.corpora, EXAMPLE_FUZZER)
206
+
207
+ @mock.patch('logging.info')
208
+ def test_download_corpus(self, mock_info):
209
+ """Tests that download corpus returns the path to the empty corpus
210
+ directory."""
211
+ self.deployment.download_corpus(EXAMPLE_FUZZER, self.corpus_dir)
212
+ mock_info.assert_called_with(
213
+ 'Not downloading corpus because no ClusterFuzz deployment.')
214
+ self.assertTrue(os.path.exists(self.corpus_dir))
215
+
216
+ @parameterized.parameterized.expand([
217
+ ('upload_build', ('commit',),
218
+ 'Not uploading latest build because no ClusterFuzz deployment.'),
219
+ ('upload_corpus', ('target', 'corpus-dir'),
220
+ 'Not uploading corpus because no ClusterFuzz deployment.'),
221
+ ('upload_crashes', tuple(),
222
+ 'Not uploading crashes because no ClusterFuzz deployment.'),
223
+ ('download_latest_build', tuple(),
224
+ 'Not downloading latest build because no ClusterFuzz deployment.')
225
+ ])
226
+ def test_noop_methods(self, method, method_args, expected_message):
227
+ """Tests that certain methods are noops for NoClusterFuzzDeployment."""
228
+ with mock.patch('logging.info') as mock_info:
229
+ method = getattr(self.deployment, method)
230
+ self.assertIsNone(method(*method_args))
231
+ mock_info.assert_called_with(expected_message)
232
+
233
+
234
+ class GetClusterFuzzDeploymentTest(unittest.TestCase):
235
+ """Tests for get_clusterfuzz_deployment."""
236
+
237
+ def setUp(self):
238
+ test_helpers.patch_environ(self)
239
+ os.environ['GITHUB_REPOSITORY'] = 'owner/myproject'
240
+
241
+ @parameterized.parameterized.expand([
242
+ (config_utils.BaseConfig.Platform.INTERNAL_GENERIC_CI,
243
+ clusterfuzz_deployment.OSSFuzz),
244
+ (config_utils.BaseConfig.Platform.INTERNAL_GITHUB,
245
+ clusterfuzz_deployment.OSSFuzz),
246
+ (config_utils.BaseConfig.Platform.EXTERNAL_GENERIC_CI,
247
+ clusterfuzz_deployment.ClusterFuzzLite),
248
+ (config_utils.BaseConfig.Platform.EXTERNAL_GITHUB,
249
+ clusterfuzz_deployment.ClusterFuzzLite),
250
+ ])
251
+ def test_get_clusterfuzz_deployment(self, platform, expected_deployment_cls):
252
+ """Tests that get_clusterfuzz_deployment returns the correct value."""
253
+ with mock.patch('config_utils.BaseConfig.platform',
254
+ return_value=platform,
255
+ new_callable=mock.PropertyMock):
256
+ with mock.patch('filestore_utils.get_filestore', return_value=None):
257
+ with mock.patch('platform_config.github._get_event_data',
258
+ return_value={}):
259
+ config = _create_config()
260
+ workspace = workspace_utils.Workspace(config)
261
+
262
+ self.assertIsInstance(
263
+ clusterfuzz_deployment.get_clusterfuzz_deployment(
264
+ config, workspace), expected_deployment_cls)
265
+
266
+
267
+ if __name__ == '__main__':
268
+ unittest.main()
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/filestore_utils.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2021 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
+ """External filestore interface. Cannot be depended on by filestore code."""
15
+ import filestore
16
+ import filestore.filesystem
17
+ import filestore.git
18
+ import filestore.github_actions
19
+ import filestore.gsutil
20
+ import filestore.no_filestore
21
+ import filestore.gitlab
22
+
23
+ FILESTORE_MAPPING = {
24
+ 'filesystem': filestore.filesystem.FilesystemFilestore,
25
+ 'gsutil': filestore.gsutil.GSUtilFilestore,
26
+ 'github-actions': filestore.github_actions.GithubActionsFilestore,
27
+ 'git': filestore.git.GitFilestore,
28
+ # TODO(metzman): Change to "no-filestore"
29
+ 'no_filestore': filestore.no_filestore.NoFilestore,
30
+ 'gitlab': filestore.gitlab.GitlabFilestore,
31
+ }
32
+
33
+
34
+ def get_filestore(config):
35
+ """Returns the correct filestore object based on the platform in |config|.
36
+ Raises an exception if there is no correct filestore for the platform."""
37
+ if config.platform == config.Platform.EXTERNAL_GITHUB:
38
+ ci_filestore = filestore.github_actions.GithubActionsFilestore(config)
39
+ if not config.git_store_repo:
40
+ return ci_filestore
41
+
42
+ return filestore.git.GitFilestore(config, ci_filestore)
43
+
44
+ filestore_cls = FILESTORE_MAPPING.get(config.filestore)
45
+ if filestore_cls is None:
46
+ raise filestore.FilestoreError(
47
+ f'Filestore: {config.filestore} doesn\'t exist.')
48
+ return filestore_cls(config)
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/cifuzz/requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ clusterfuzz==2.5.9
2
+ requests==2.28.0
3
+ protobuf==3.20.2
4
+ gsutil==5.20
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/uploader/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from ubuntu:16.04
2
+
3
+ RUN apt-get update && apt-get upgrade -y
4
+ RUN apt-get install -y curl
5
+
6
+ ENTRYPOINT ["curl", "--retry", "5", "-X", "PUT", "-T"]
7
+
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import * as vscode from 'vscode';
18
+ import {println} from '../logger';
19
+ import {commandHistory} from '../commandUtils';
20
+ import {
21
+ hasOssFuzzInWorkspace,
22
+ getOssFuzzWorkspaceProjectName,
23
+ setStatusText,
24
+ } from '../utils';
25
+ import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
26
+
27
+ export async function cmdInputCollectorBuildFuzzersFromWorkspace() {
28
+ let ossFuzzProjectName = '';
29
+ // First determine if we have a name in the workspace
30
+ if (await hasOssFuzzInWorkspace()) {
31
+ /**
32
+ * The fuzzers are in the workspace, as opposed to e.g. the oss-fuzz dirctory.
33
+ */
34
+ ossFuzzProjectName = await getOssFuzzWorkspaceProjectName();
35
+ } else {
36
+ // If we did not have that, ask the user.
37
+
38
+ const ossFuzzProjectNameInput = await vscode.window.showInputBox({
39
+ value: '',
40
+ placeHolder: 'The OSS-Fuzz project name',
41
+ });
42
+ if (!ossFuzzProjectNameInput) {
43
+ println('Did not get a ossFuzzTargetProject');
44
+ return false;
45
+ }
46
+ ossFuzzProjectName = ossFuzzProjectNameInput.toString();
47
+ }
48
+
49
+ // Create an history object
50
+ const args = new Object({
51
+ projectName: ossFuzzProjectName,
52
+ sanitizer: '',
53
+ toClean: false,
54
+ });
55
+
56
+ const commandObject = new Object({
57
+ commandType: 'oss-fuzz.WSBuildFuzzers',
58
+ Arguments: args,
59
+ dispatcherFunc: cmdDispatchBuildFuzzersFromWorkspace,
60
+ });
61
+ console.log('L1: ' + commandHistory.length);
62
+ commandHistory.push(commandObject);
63
+
64
+ await cmdDispatchBuildFuzzersFromWorkspace(args);
65
+ return true;
66
+ }
67
+
68
+ async function cmdDispatchBuildFuzzersFromWorkspace(args: any) {
69
+ await setStatusText('Building fuzzers: starting');
70
+ const res = await buildFuzzersFromWorkspace(
71
+ args.projectName,
72
+ args.sanitizer,
73
+ args.toClean
74
+ );
75
+ if (res) {
76
+ await setStatusText('Building fuzzers: finished');
77
+ } else {
78
+ await setStatusText('Building fuzzers: failed');
79
+ }
80
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdDispatcherGenerateClusterfuzzLite.ts ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ /**
18
+ * Command for generating template fuzzers. This is a short-cut for rapid
19
+ * prototyping as well as an archive for inspiration.
20
+ */
21
+ import * as vscode from 'vscode';
22
+ import {setStatusText} from '../utils';
23
+
24
+ import {setupProjectInitialFiles} from '../projectIntegrationHelper';
25
+
26
+ export async function cmdDispatcherGenerateClusterfuzzLite(
27
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
+ _context: vscode.ExtensionContext
29
+ ) {
30
+ await setStatusText('Creating OSS-Fuzz setup: starting');
31
+ const res = await setupProjectInitialFiles(true);
32
+ if (res) {
33
+ await setStatusText('Creating OSS-Fuzz setup: finished');
34
+ } else {
35
+ await setStatusText('Creating OSS-Fuzz setup: failed');
36
+ }
37
+ return;
38
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdEndToEndCoverage.ts ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import * as vscode from 'vscode';
18
+ const fs = require('fs');
19
+ import {println} from '../logger';
20
+ import {commandHistory} from '../commandUtils';
21
+ import {buildFuzzersFromWorkspace, runFuzzerHandler} from '../ossfuzzWrappers';
22
+ import {listFuzzersForProject, systemSync, setStatusText} from '../utils';
23
+ import {
24
+ compareLocalToRemoteCoverage,
25
+ loadCoverageIntoWorkspace,
26
+ } from '../coverageHelper';
27
+ import {extensionConfig} from '../config';
28
+
29
+ /**
30
+ * Performs the activities:
31
+ * 1) Build a project using address sanitizer
32
+ * 2) Run each fuzzer of the project, saving corpus
33
+ * 3) Build project using coverage sanitizer
34
+ * 4) Collect coverage
35
+ * @param context
36
+ * @returns
37
+ */
38
+ export async function runEndToEndAndGetCoverage(
39
+ context: vscode.ExtensionContext
40
+ ) {
41
+ println('Getting code coverage');
42
+ await setStatusText('end-to-end coverage: getting input');
43
+ const ossFuzzProjectNameInput = await vscode.window.showInputBox({
44
+ value: '',
45
+ placeHolder: 'The OSS-Fuzz project name',
46
+ });
47
+ if (!ossFuzzProjectNameInput) {
48
+ println('Did not get a ossFuzzTargetProject');
49
+ return;
50
+ }
51
+ const secondsToRunEachFuzzer = await vscode.window.showInputBox({
52
+ value: '',
53
+ placeHolder: 'Seconds to run each fuzzer',
54
+ });
55
+ if (!secondsToRunEachFuzzer) {
56
+ println('Did not get number of seconds to run each fuzzer');
57
+ return;
58
+ }
59
+
60
+ // Create an history object
61
+ const args = new Object({
62
+ projectName: ossFuzzProjectNameInput.toString(),
63
+ secondsToRun: secondsToRunEachFuzzer.toString(),
64
+ vsContext: context,
65
+ });
66
+
67
+ const commandObject = new Object({
68
+ commandType: 'oss-fuzz.cmdDispatchEndToEndRun',
69
+ Arguments: args,
70
+ dispatcherFunc: cmdDispatchEndToEndRun,
71
+ });
72
+ console.log('L1: ' + commandHistory.length);
73
+ commandHistory.push(commandObject);
74
+
75
+ await cmdDispatchEndToEndRun(args);
76
+ return;
77
+ }
78
+
79
+ async function cmdDispatchEndToEndRun(args: any) {
80
+ await setStatusText('end-to-end coverage: starting');
81
+ const res = await endToEndRun(
82
+ args.projectName,
83
+ args.secondsToRun,
84
+ args.vsContext
85
+ );
86
+ if (res) {
87
+ await setStatusText('end-to-end coverage: finished succesfully');
88
+ } else {
89
+ await setStatusText('end-to-end coverage: failed');
90
+ }
91
+ return;
92
+ }
93
+
94
+ async function endToEndRun(
95
+ ossFuzzProjectNameInput: string,
96
+ secondsToRunEachFuzzer: string,
97
+ context: vscode.ExtensionContext
98
+ ) {
99
+ await setStatusText('end-to-end coverage: build with ASAN');
100
+ vscode.window.showInformationMessage(
101
+ 'Building project: ' + ossFuzzProjectNameInput.toString()
102
+ );
103
+ if (
104
+ (await buildFuzzersFromWorkspace(
105
+ ossFuzzProjectNameInput.toString(),
106
+ '',
107
+ true
108
+ )) === false
109
+ ) {
110
+ println('Failed to build project');
111
+ return false;
112
+ }
113
+ println('Build projects');
114
+
115
+ // List all of the fuzzers in the project
116
+ const fuzzersInProject = await listFuzzersForProject(
117
+ ossFuzzProjectNameInput,
118
+ extensionConfig.ossFuzzPepositoryWorkPath
119
+ );
120
+
121
+ // Run all of the fuzzers in the project
122
+ await setStatusText('end-to-end coverage: collecting corpus');
123
+ println('Fuzzers found in project: ' + fuzzersInProject.toString());
124
+ println('Running each of the fuzzers to collect a corpus');
125
+ for (const fuzzName of fuzzersInProject) {
126
+ println('Running fuzzer: ' + fuzzName);
127
+ await setStatusText('end-to-end coverage: collecting corpus: ' + fuzzName);
128
+ // Corpus directory
129
+ const fuzzerCorpusPath =
130
+ extensionConfig.ossFuzzPepositoryWorkPath +
131
+ '/build/corpus/' +
132
+ ossFuzzProjectNameInput +
133
+ '/' +
134
+ fuzzName;
135
+
136
+ await systemSync('mkdir', ['-p', fuzzerCorpusPath]);
137
+
138
+ await runFuzzerHandler(
139
+ ossFuzzProjectNameInput,
140
+ fuzzName,
141
+ secondsToRunEachFuzzer.toString(),
142
+ fuzzerCorpusPath
143
+ );
144
+ }
145
+
146
+ // Build with code coverage
147
+ println('Building project with coverage sanitizer');
148
+ await setStatusText('end-to-end coverage: building with coverage');
149
+ await buildFuzzersFromWorkspace(
150
+ ossFuzzProjectNameInput.toString(),
151
+ 'coverage',
152
+ true
153
+ );
154
+
155
+ // Run coverage command
156
+ println('Collecting code coverage');
157
+ await setStatusText('end-to-end coverage: collecting coverage');
158
+ const args: Array<string> = [
159
+ extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
160
+ 'coverage',
161
+ '--port',
162
+ '',
163
+ '--no-corpus-download',
164
+ ossFuzzProjectNameInput.toString(),
165
+ ];
166
+ await systemSync('python3', args);
167
+ await setStatusText('end-to-end coverage: finished collecting coverage');
168
+ println('Load coverage report with the command:');
169
+ println(
170
+ 'python3 -m http.server 8008 --directory /tmp/oss-fuzz/build/out/' +
171
+ ossFuzzProjectNameInput.toString() +
172
+ '/report/'
173
+ );
174
+
175
+ println('Trying to load code coverage in IDE');
176
+ const allCovPath =
177
+ extensionConfig.ossFuzzPepositoryWorkPath +
178
+ '/build/out/' +
179
+ ossFuzzProjectNameInput.toString() +
180
+ '/textcov_reports/all_cov.json';
181
+ if (fs.existsSync(allCovPath)) {
182
+ const generatedCodeCoverageFile = vscode.Uri.file(allCovPath);
183
+ await loadCoverageIntoWorkspace(context, generatedCodeCoverageFile);
184
+ }
185
+
186
+ await compareLocalToRemoteCoverage(
187
+ context,
188
+ ossFuzzProjectNameInput.toString()
189
+ );
190
+
191
+ return true;
192
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdRedo.ts ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import {commandHistory} from '../commandUtils';
18
+
19
+ /**
20
+ * Rerun the latest command
21
+ */
22
+ export async function cmdDispatcherRe() {
23
+ if (commandHistory.length === 0) {
24
+ console.log('command history is empty');
25
+ return false;
26
+ }
27
+
28
+ const commandObj: any = commandHistory[commandHistory.length - 1];
29
+
30
+ console.log('Redoing');
31
+ console.log(commandObj.commandType);
32
+ await commandObj.dispatcherFunc(commandObj.Arguments);
33
+ //await commandObj.dispatcherFunc(commandObj.args);
34
+ return true;
35
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import * as vscode from 'vscode';
18
+ const fs = require('fs');
19
+ import {println} from '../logger';
20
+ import {commandHistory} from '../commandUtils';
21
+ import {systemSyncLogIfFailure} from '../utils';
22
+ import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
23
+ import {extensionConfig} from '../config';
24
+ const readline = require('readline');
25
+
26
+ export async function cmdInputCollectorReproduceTestcase() {
27
+ // Runs a fuzzer from a given project.
28
+ const crashFileInput = await vscode.window.showInputBox({
29
+ value: '',
30
+ placeHolder: 'The ID of the testcase.',
31
+ });
32
+ if (!crashFileInput) {
33
+ return;
34
+ }
35
+ // Create an history object and append it to the command history.
36
+ const args = new Object({
37
+ crashFile: crashFileInput.toString(),
38
+ });
39
+
40
+ const commandObject = new Object({
41
+ commandType: 'oss-fuzz.ReproduceFuzzer',
42
+ Arguments: args,
43
+ dispatcherFunc: cmdDispatchReproduceTestcase,
44
+ });
45
+ commandHistory.push(commandObject);
46
+
47
+ await cmdDispatchReproduceTestcase(args);
48
+ return true;
49
+ }
50
+
51
+ async function cmdDispatchReproduceTestcase(args: any) {
52
+ await reproduceTestcase(args.crashFile);
53
+ }
54
+
55
+ export async function reproduceTestcase(crashInfoFileInput: string) {
56
+ println('Reproducing testcase for ' + crashInfoFileInput);
57
+ println('Checking directory: ' + extensionConfig.crashesDirectory);
58
+
59
+ const crashInfoFile =
60
+ extensionConfig.crashesDirectory + '/' + crashInfoFileInput + '.info';
61
+ println(crashInfoFile);
62
+ try {
63
+ if (fs.existsSync(crashInfoFile)) {
64
+ println('File exists');
65
+ } else {
66
+ println('Crash file does not exist');
67
+ return;
68
+ }
69
+ } catch (err) {
70
+ console.error(err);
71
+ return;
72
+ }
73
+
74
+ // At this point the file exists
75
+ const r = readline.createInterface({
76
+ input: fs.createReadStream(crashInfoFile),
77
+ });
78
+
79
+ let targetProject = 'N/A';
80
+ let targetFuzzer = 'N/A';
81
+ // Logic for passing the file. This is based off of clusterfuzz monorail reports,
82
+ // and the intention is the file needs to be a copy of:
83
+ //
84
+ // Project: project-name
85
+ // Fuzzing Engine: libFuzzer
86
+ // Fuzz Target: fuzzer-name
87
+ //
88
+ // Example:
89
+ // The following URL: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59747
90
+ // has the bug information:
91
+ // """
92
+ // Project: my-fuzzing-project
93
+ // Fuzzing Engine: libFuzzer
94
+ // Fuzz Target: the-fuzzer-name-fuzz-parseXX
95
+ // Job Type: libfuzzer_asan_my-fuzzing-project
96
+ // Platform Id: linux
97
+ // """
98
+ // and a link to a reproducer test case:
99
+ // https://oss-fuzz.com/download?testcase_id=5009071179431936
100
+ // which, when accessed will download the file
101
+ // clusterfuzz-testcase-minimized-flb-it-fuzz-config_map_fuzzer_OSSFUZZ-5009071179431936
102
+ //
103
+ // To enable reproducing of this issue we need to:
104
+ // - 1) Download the crash file and place it in the directory given in config.ts
105
+ // and "crashesDirectory" variable.
106
+ // - 2) create a file "5009071179431936.info" and paste the information above
107
+ // (Project:... Fuzz Target: ...) into the file. This information is
108
+ // needed because we need to know project name and fuzzer name in order
109
+ // to reproduce the crash.
110
+ // - 3) the reproducer can now be reproduced using the reproduce command
111
+ // with argument "5009071179431936" as argument.
112
+ r.on('line', (text: string) => {
113
+ println(text);
114
+ if (text.startsWith('Project: ')) {
115
+ println('Starts with project');
116
+ println(text.split('Project: ').toString());
117
+ targetProject = text.split('Project: ')[1];
118
+ } else if (text.startsWith('Fuzzing Engine: ')) {
119
+ println('Starts with fuzzing engine');
120
+ } else if (text.startsWith('Fuzz Target:')) {
121
+ println('Starts with Fuzz Target');
122
+ targetFuzzer = text.split('Fuzz Target: ')[1];
123
+ } else if (text.startsWith('Job Type:')) {
124
+ println('Starts with Job Type');
125
+ }
126
+ });
127
+
128
+ r.on('close', async () => {
129
+ println('Target project: ' + targetProject);
130
+ println('Target fuzzer: ' + targetFuzzer);
131
+
132
+ // Build a fresh version of the project.
133
+ const buildResult: boolean = await buildFuzzersFromWorkspace(
134
+ targetProject,
135
+ '',
136
+ true
137
+ );
138
+ if (!buildResult) {
139
+ println('Failed to build fuzzers');
140
+ return false;
141
+ }
142
+
143
+ // We have a fresh build of the project, proceed to reproduce the testcase.
144
+ const crashInputTestCase =
145
+ extensionConfig.crashesDirectory +
146
+ '/' +
147
+ 'clusterfuzz-testcase-minimized-' +
148
+ targetFuzzer +
149
+ '-' +
150
+ crashInfoFileInput;
151
+ // Run reproduce command against the target file
152
+ // Build the fuzzers using OSS-Fuzz infrastructure.
153
+ const cmdToExec = 'python3';
154
+ const args = [
155
+ extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
156
+ 'reproduce',
157
+ targetProject,
158
+ targetFuzzer,
159
+ crashInputTestCase,
160
+ ];
161
+ if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
162
+ println('Failed to reproduce testcase');
163
+ }
164
+
165
+ return true;
166
+ });
167
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFI.ts ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2024 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import {runFuzzIntrospector} from '../fuzzIntrospectorHelper';
18
+
19
+ /**
20
+ * Function for setting up Fuzz Introspector by way of a Python virtual env.
21
+ */
22
+ export async function runFuzzIntrospectorHandler() {
23
+ runFuzzIntrospector();
24
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFuzzer.ts ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import * as vscode from 'vscode';
18
+ import {println} from '../logger';
19
+ import {commandHistory} from '../commandUtils';
20
+ import {runFuzzerHandler} from '../ossfuzzWrappers';
21
+
22
+ export async function cmdInputCollectorRunSpecificFuzzer() {
23
+ let projectNameArg = '';
24
+ let fuzzerName = '';
25
+ let secondsToRun = '';
26
+
27
+ // Runs a fuzzer from a given project.
28
+ const projectNameFromPrompt = await vscode.window.showInputBox({
29
+ value: '',
30
+ placeHolder: 'Type a project name',
31
+ });
32
+ if (!projectNameFromPrompt) {
33
+ println('Failed to get project name');
34
+ return;
35
+ }
36
+ projectNameArg = projectNameFromPrompt.toString();
37
+ const fuzzerNameFromPrompt = await vscode.window.showInputBox({
38
+ value: '',
39
+ placeHolder: 'Type a fuzzer name',
40
+ });
41
+ if (!fuzzerNameFromPrompt) {
42
+ println('Failed to get fuzzer name');
43
+ return;
44
+ }
45
+ fuzzerName = fuzzerNameFromPrompt.toString();
46
+ const secondsToRunInp = await vscode.window.showInputBox({
47
+ value: '',
48
+ placeHolder: 'Type the number of seconds to run the fuzzer',
49
+ });
50
+ if (!secondsToRunInp) {
51
+ return;
52
+ }
53
+ secondsToRun = secondsToRunInp.toString();
54
+
55
+ // Create an history object
56
+ const args = new Object({
57
+ projectName: projectNameArg,
58
+ fuzzerName: fuzzerName,
59
+ secondsToRun: secondsToRun,
60
+ fuzzerCorpusPath: '',
61
+ });
62
+
63
+ const commandObject = new Object({
64
+ commandType: 'oss-fuzz.RunFuzzer',
65
+ Arguments: args,
66
+ dispatcherFunc: cmdDispatchRunFuzzerHandler,
67
+ });
68
+ console.log('L1: ' + commandHistory.length);
69
+ commandHistory.push(commandObject);
70
+
71
+ await cmdDispatchRunFuzzerHandler(args);
72
+ return true;
73
+ }
74
+
75
+ async function cmdDispatchRunFuzzerHandler(args: any) {
76
+ await runFuzzerHandler(
77
+ args.projectName,
78
+ args.fuzzerName,
79
+ args.secondsToRun,
80
+ args.fuzzerCorpusPath
81
+ );
82
+ return;
83
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupCIFuzz.ts ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import * as vscode from 'vscode';
18
+ import {println} from '../logger';
19
+ import {determineWorkspaceLanguage} from '../utils';
20
+ import {cifuzzGenerator} from '../cifuzz';
21
+
22
+ export async function setupCIFuzzHandler() {
23
+ const workspaceFolder = vscode.workspace.workspaceFolders;
24
+ if (!workspaceFolder) {
25
+ return false;
26
+ }
27
+
28
+ const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
29
+
30
+ /**
31
+ * Go through GitHub workflows to find potential traces of CIFuzz
32
+ */
33
+ const githubWorkflowsPath = vscode.Uri.file(wsPath + '/.github/workflows');
34
+ try {
35
+ await vscode.workspace.fs.readDirectory(githubWorkflowsPath);
36
+ } catch {
37
+ println('Did not find a workflows path.');
38
+ return false;
39
+ }
40
+
41
+ for (const [name, type] of await vscode.workspace.fs.readDirectory(
42
+ githubWorkflowsPath
43
+ )) {
44
+ // Skip directories.
45
+ if (type === 2) {
46
+ continue;
47
+ }
48
+
49
+ // Read the files.
50
+ println('Is a file');
51
+ const workflowFile = vscode.Uri.file(wsPath + '/.github/workflows/' + name);
52
+ const doc = await vscode.workspace.openTextDocument(workflowFile);
53
+ if (doc.getText().includes('cifuzz')) {
54
+ println('Found existing CIFuzz, will not continue.');
55
+ return false;
56
+ }
57
+ }
58
+
59
+ println('Did not find CIFuzz, creating one.');
60
+ const projectName = await vscode.window.showInputBox({
61
+ value: '',
62
+ placeHolder: 'OSS-Fuzz project name',
63
+ });
64
+ if (!projectName) {
65
+ println('Failed to get project name');
66
+ return false;
67
+ }
68
+
69
+ /*
70
+ * There is no CIFuzz found, so we create one.
71
+ */
72
+ // Determine the language of the workspace.
73
+ const targetLanguage = await determineWorkspaceLanguage();
74
+ println('Target language: ' + targetLanguage);
75
+
76
+ // Generate a CIFuzz workflow text.
77
+ const cifuzzWorkflowText = cifuzzGenerator(targetLanguage, projectName, 30);
78
+
79
+ // Create the CIFuzz .yml file and write the contents to it to path
80
+ // .github/workflows/cifuzz.yml
81
+ const cifuzzYml = vscode.Uri.file(wsPath + '/.github/workflows/cifuzz.yml');
82
+ const wsedit = new vscode.WorkspaceEdit();
83
+ wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
84
+ wsedit.insert(cifuzzYml, new vscode.Position(0, 0), cifuzzWorkflowText);
85
+ vscode.workspace.applyEdit(wsedit);
86
+ return true;
87
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdTemplate.ts ADDED
@@ -0,0 +1,357 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ /**
18
+ * Command for generating template fuzzers. This is a short-cut for rapid
19
+ * prototyping as well as an archive for inspiration.
20
+ */
21
+ import * as vscode from 'vscode';
22
+ import {println} from '../logger';
23
+
24
+ export const cLangSimpleStringFuzzer = `#include <stdint.h>
25
+ #include <string.h>
26
+ #include <stdlib.h>
27
+
28
+ int
29
+ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
30
+ {
31
+ char *new_str = (char *)malloc(size+1);
32
+ if (new_str == NULL){
33
+ return 0;
34
+ }
35
+ memcpy(new_str, data, size);
36
+ new_str[size] = '\\0';
37
+
38
+ // Insert fuzzer contents here
39
+ // fuzz data in new_str
40
+
41
+ // end of fuzzer contents
42
+
43
+ free(new_str);
44
+ return 0;
45
+ }`;
46
+
47
+ const cLangFileInputFuzzer = `int
48
+ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49
+ {
50
+ char filename[256];
51
+ sprintf(filename, "/tmp/libfuzzer.%d", getpid());
52
+
53
+ // Create a file on the filesystem with fuzzer data in it
54
+ FILE *fp = fopen(filename, "wb");
55
+ if (!fp) {
56
+ return 0;
57
+ }
58
+ fwrite(data, size, 1, fp);
59
+ fclose(fp);
60
+
61
+ // Fuzzer logic here. Use the file as a source of data.
62
+
63
+ // Fuzzer logic end
64
+
65
+ // Clean up the file.
66
+ unlink(filename);
67
+
68
+ return 0;
69
+ }`;
70
+
71
+ const cLangBareTemplateFuzzer = `int
72
+ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
73
+ {
74
+ return 0;
75
+ }`;
76
+
77
+ const cppLangBareTemplateFuzzer = `extern "C" int
78
+ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
79
+ {
80
+ return 0;
81
+ }`;
82
+
83
+ const cppLangStdStringTemplateFuzzer = `extern "C" int
84
+ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
85
+ {
86
+ std::string input(reinterpret_cast<const char*>(data), size);
87
+
88
+ return 0;
89
+ }`;
90
+
91
+ export const cppLangFDPTemplateFuzzer = `#include <fuzzer/FuzzedDataProvider.h>
92
+
93
+ #include <string>
94
+
95
+ extern "C" int
96
+ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
97
+ {
98
+ FuzzedDataProvider fdp(data, size);
99
+
100
+ // Extract higher level data types used for fuzzing, e.g.
101
+ // int ran_int = fdp.ConsumeIntegralInRange<int>(1, 1024);
102
+ // std::string s = fdp.ConsumeRandomLengthString();
103
+
104
+ return 0;
105
+ }`;
106
+
107
+ const cppLangFileInputFuzzer = `extern "C" int
108
+ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
109
+ {
110
+ char filename[256];
111
+ sprintf(filename, "/tmp/libfuzzer.%d", getpid());
112
+
113
+ FILE *fp = fopen(filename, "wb");
114
+ if (!fp) {
115
+ return 0;
116
+ }
117
+ fwrite(data, size, 1, fp);
118
+ fclose(fp);
119
+
120
+ // Fuzzer logic here
121
+
122
+ // Fuzzer logic end
123
+
124
+ unlink(filename);
125
+ }`;
126
+
127
+ const pythonLangBareTemplate = `import sys
128
+ import atheris
129
+
130
+
131
+ def TestOneInput(fuzz_bytes):
132
+ return
133
+
134
+
135
+ def main():
136
+ atheris.Setup(sys.argv, TestOneInput)
137
+ atheris.Fuzz()
138
+
139
+
140
+ if __name__ == "__main__":
141
+ main()`;
142
+
143
+ export const pythonLangFileInputFuzzer = `import sys
144
+ import atheris
145
+
146
+ @atheris.instrument_func
147
+ def TestOneInput(data):
148
+ # Write fuzz data to a file
149
+ with open('/tmp/fuzz_input.b') as f:
150
+ f.write(data)
151
+
152
+ # Use '/tmp/fuzz_input.b' as input to file handling logic.
153
+
154
+
155
+ def main():
156
+ atheris.instrument_all()
157
+ atheris.Setup(sys.argv, TestOneInput)
158
+ atheris.Fuzz()
159
+
160
+
161
+ if __name__ == "__main__":
162
+ main()`;
163
+
164
+ const pythonLongFdpTemplate = `import sys
165
+ import atheris
166
+
167
+ def TestOneInput(fuzz_bytes):
168
+ fdp = atheris.FuzzedDataProvider(fuzz_bytes)
169
+ return
170
+
171
+ def main():
172
+ atheris.Setup(sys.argv, TestOneInput)
173
+ atheris.Fuzz()
174
+
175
+ if __name__ == "__main__":
176
+ main()`;
177
+
178
+ export const javaLangBareTemplate = `import com.code_intelligence.jazzer.api.FuzzedDataProvider;
179
+ public class SampleFuzzer {
180
+ public static void fuzzerTestOneInput(FuzzedDataProvider fdp) {
181
+ // Use fdp to create arbitrary types seeded with fuzz data
182
+ }
183
+ }
184
+ `;
185
+
186
+ /**
187
+ * C templates
188
+ */
189
+ async function cTemplates() {
190
+ let template = '';
191
+ const result = await vscode.window.showQuickPick(
192
+ ['Bare template', 'Null-terminated string input', 'File input'],
193
+ {
194
+ placeHolder: 'Pick which template',
195
+ }
196
+ );
197
+ vscode.window.showInformationMessage(`Got: ${result}`);
198
+
199
+ if (result === 'Null-terminated string input') {
200
+ template = cLangSimpleStringFuzzer;
201
+ } else if (result === 'File input') {
202
+ template = cLangFileInputFuzzer;
203
+ } else if (result === 'Bare template') {
204
+ template = cLangBareTemplateFuzzer;
205
+ } else {
206
+ template = 'empty';
207
+ }
208
+ const workspaceFolder = vscode.workspace.workspaceFolders;
209
+ if (!workspaceFolder) {
210
+ return;
211
+ }
212
+
213
+ const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
214
+
215
+ const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.c');
216
+ const wsedit = new vscode.WorkspaceEdit();
217
+ wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
218
+ wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
219
+ vscode.workspace.applyEdit(wsedit);
220
+ return;
221
+ }
222
+
223
+ /**
224
+ * CPP templates
225
+ */
226
+ async function cppTemplates() {
227
+ let template = '';
228
+ const result = await vscode.window.showQuickPick(
229
+ [
230
+ 'Bare template',
231
+ 'Simple CPP string',
232
+ 'File input fuzzer',
233
+ 'Fuzzed data provider',
234
+ ],
235
+ {
236
+ placeHolder: 'Pick which template',
237
+ }
238
+ );
239
+ vscode.window.showInformationMessage(`Got: ${result}`);
240
+
241
+ if (result === 'Bare template') {
242
+ template = cppLangBareTemplateFuzzer;
243
+ } else if (result === 'Simple CPP string') {
244
+ template = cppLangStdStringTemplateFuzzer;
245
+ } else if (result === 'File input fuzzer') {
246
+ template = cppLangFileInputFuzzer;
247
+ } else if (result === 'Fuzzed data provider') {
248
+ template = cppLangFDPTemplateFuzzer;
249
+ } else {
250
+ template = 'empty';
251
+ }
252
+ const workspaceFolder = vscode.workspace.workspaceFolders;
253
+ if (!workspaceFolder) {
254
+ return;
255
+ }
256
+
257
+ const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
258
+
259
+ const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.cpp');
260
+ const wsedit = new vscode.WorkspaceEdit();
261
+ wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
262
+ wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
263
+ vscode.workspace.applyEdit(wsedit);
264
+ return;
265
+ }
266
+
267
+ /**
268
+ * Python templates
269
+ */
270
+ async function pythonTepmlates() {
271
+ let template = '';
272
+ const result = await vscode.window.showQuickPick(
273
+ ['Bare template', 'Fuzzed Data Provider', 'File input fuzzer'],
274
+ {
275
+ placeHolder: 'Pick which template',
276
+ }
277
+ );
278
+ vscode.window.showInformationMessage(`Got: ${result}`);
279
+
280
+ if (result === 'Fuzzed Data Provider') {
281
+ template = pythonLongFdpTemplate;
282
+ } else if (result === 'Bare template') {
283
+ template = pythonLangBareTemplate;
284
+ } else if (result === 'File input fuzzer') {
285
+ template = pythonLangFileInputFuzzer;
286
+ } else {
287
+ template = 'empty';
288
+ }
289
+ const workspaceFolder = vscode.workspace.workspaceFolders;
290
+ if (!workspaceFolder) {
291
+ return;
292
+ }
293
+
294
+ const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
295
+
296
+ const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.py');
297
+ const wsedit = new vscode.WorkspaceEdit();
298
+ wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
299
+ wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
300
+ vscode.workspace.applyEdit(wsedit);
301
+ return;
302
+ }
303
+
304
+ /**
305
+ * Java templates
306
+ */
307
+ async function javaTemplates() {
308
+ let template = '';
309
+ const result = await vscode.window.showQuickPick(['Bare template'], {
310
+ placeHolder: 'Pick which template',
311
+ });
312
+ vscode.window.showInformationMessage(`Got: ${result}`);
313
+
314
+ if (result === 'Bare template') {
315
+ template = javaLangBareTemplate;
316
+ } else {
317
+ template = 'empty';
318
+ }
319
+ const workspaceFolder = vscode.workspace.workspaceFolders;
320
+ if (!workspaceFolder) {
321
+ return;
322
+ }
323
+
324
+ const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
325
+
326
+ const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.java');
327
+ const wsedit = new vscode.WorkspaceEdit();
328
+ wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
329
+ wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
330
+ vscode.workspace.applyEdit(wsedit);
331
+ return;
332
+ }
333
+
334
+ export async function cmdDispatcherTemplate(context: vscode.ExtensionContext) {
335
+ println('Creating template');
336
+ const options: {
337
+ [key: string]: (context: vscode.ExtensionContext) => Promise<void>;
338
+ } = {
339
+ C: cTemplates,
340
+ CPP: cppTemplates,
341
+ Python: pythonTepmlates,
342
+ Java: javaTemplates,
343
+ };
344
+
345
+ const quickPick = vscode.window.createQuickPick();
346
+ quickPick.items = Object.keys(options).map(label => ({label}));
347
+ quickPick.onDidChangeSelection(selection => {
348
+ if (selection[0]) {
349
+ options[selection[0].label](context).catch(console.error);
350
+ }
351
+ });
352
+ quickPick.onDidHide(() => quickPick.dispose());
353
+ quickPick.placeholder = 'Pick language';
354
+ quickPick.show();
355
+
356
+ return;
357
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzerCFLite.ts ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import path = require('path');
18
+ import * as vscode from 'vscode';
19
+ import {println} from '../logger';
20
+ import {
21
+ runFuzzerHandlerCFLite,
22
+ buildFuzzersFromWorkspaceClusterfuzzLite,
23
+ } from '../ossfuzzWrappers';
24
+ import {setStatusText} from '../utils';
25
+ import {commandHistory} from '../commandUtils';
26
+ import {extensionConfig} from '../config';
27
+
28
+ /**
29
+ * Does an end-to-end test of a project/fuzzer. This is done by
30
+ * first building the project and then running the fuzzer.
31
+ * @param context
32
+ * @returns
33
+ */
34
+
35
+ export async function cmdInputCollectorTestFuzzerCFLite() {
36
+ setStatusText('Testing specific fuzzer: getting input');
37
+ // Get the fuzzer to run
38
+ const fuzzerNameInput = await vscode.window.showInputBox({
39
+ value: '',
40
+ placeHolder: 'Type a fuzzer name',
41
+ });
42
+ if (!fuzzerNameInput) {
43
+ println('Failed to get fuzzer name');
44
+ return;
45
+ }
46
+
47
+ // Create the args object for the dispatcher
48
+ const args = new Object({
49
+ fuzzerName: fuzzerNameInput.toString(),
50
+ });
51
+
52
+ // Create a dispatcher object.
53
+ const commandObject = new Object({
54
+ commandType: 'oss-fuzz.TestFuzzerCFLite',
55
+ Arguments: args,
56
+ dispatcherFunc: cmdDispatchTestFuzzerHandlerCFLite,
57
+ });
58
+ commandHistory.push(commandObject);
59
+
60
+ await cmdDispatchTestFuzzerHandlerCFLite(args);
61
+ }
62
+
63
+ async function cmdDispatchTestFuzzerHandlerCFLite(args: any) {
64
+ // Build the project
65
+ setStatusText('Test specific fuzzer: building fuzzers in workspace');
66
+ if (!(await buildFuzzersFromWorkspaceClusterfuzzLite())) {
67
+ println('Build projects');
68
+ return;
69
+ }
70
+
71
+ const workspaceFolder = vscode.workspace.workspaceFolders;
72
+ if (!workspaceFolder) {
73
+ return;
74
+ }
75
+
76
+ const pathOfLocal = workspaceFolder[0].uri.path;
77
+ println('path of local: ' + pathOfLocal);
78
+
79
+ // Run the fuzzer for 10 seconds
80
+ println('Running fuzzer');
81
+ setStatusText('Test specific fuzzer: running fuzzer ' + args.fuzzerName);
82
+ await runFuzzerHandlerCFLite(
83
+ pathOfLocal,
84
+ args.fuzzerName,
85
+ extensionConfig.numberOfSecondsForTestRuns.toString()
86
+ );
87
+ setStatusText('Test specific fuzzer: test completed of ' + args.fuzzerName);
88
+ return;
89
+ }
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/extension.ts ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 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
+ ////////////////////////////////////////////////////////////////////////////////
16
+
17
+ import * as vscode from 'vscode';
18
+
19
+ import {clearCoverage} from './coverageHelper';
20
+ import {println} from './logger';
21
+
22
+ // Import the command dispatcher functions
23
+ import {cmdInputCollectorRunSpecificFuzzer} from './commands/cmdRunFuzzer';
24
+ import {cmdInputCollectorBuildFuzzersFromWorkspace} from './commands/cmdBuildFuzzerFromWorkspace';
25
+ import {cmdInputCollectorBuildFuzzersFromWorkspaceCFLite} from './commands/cmdBuildFuzzerFromWorkspaceCFLite';
26
+ import {cmdInputCollectorTestFuzzerCFLite} from './commands/cmdTestFuzzerCFLite';
27
+ import {cmdDispatcherRe} from './commands/cmdRedo';
28
+ import {setupCIFuzzHandler} from './commands/cmdSetupCIFuzz';
29
+ import {cmdInputCollectorTestFuzzer} from './commands/cmdTestFuzzer';
30
+ import {displayCodeCoverageFromOssFuzz} from './commands/cmdDisplayCoverage';
31
+ import {createOssFuzzSetup} from './commands/cmdCreateOSSFuzzSetup';
32
+ import {runEndToEndAndGetCoverage} from './commands/cmdEndToEndCoverage';
33
+ import {listFuzzersHandler} from './commands/cmdListFuzzers';
34
+ import {cmdInputCollectorReproduceTestcase} from './commands/cmdReproduceTestcase';
35
+ import {cmdDispatcherTemplate} from './commands/cmdTemplate';
36
+ import {runGetOptimalTargetsHandler} from './commands/cmdFIGetOptimalTargets';
37
+ import {setUpFuzzIntrospectorHandler} from './commands/cmdSetupFI';
38
+ import {runFuzzIntrospectorHandler} from './commands/cmdRunFI';
39
+ import {cmdDispatcherGenerateClusterfuzzLite} from './commands/cmdDispatcherGenerateClusterfuzzLite';
40
+ import {setUpOssFuzzHandler} from './commands/cmdSetupOSSFuzz';
41
+ import {setOssFuzzPath} from './commands/cmdSetOSSFuzzPath';
42
+ import {extensionConfig} from './config';
43
+
44
+ /**
45
+ * Extension entrypoint. Activate the extension and register the commands.
46
+ */
47
+ export function activate(context: vscode.ExtensionContext) {
48
+ console.log('Activating extension)');
49
+ extensionConfig.printConfig();
50
+ println('OSS-Fuzz extension is now active!');
51
+
52
+ // Command registration
53
+ context.subscriptions.push(
54
+ vscode.commands.registerCommand('oss-fuzz.SetUp', async () => {
55
+ println('CMD start: SetUp');
56
+ await setUpOssFuzzHandler();
57
+ println('CMD end: SetUp');
58
+ })
59
+ );
60
+
61
+ context.subscriptions.push(
62
+ vscode.commands.registerCommand('oss-fuzz.RunFuzzer', async () => {
63
+ println('CMD start: Run Fuzzer');
64
+ //await runFuzzerHandler('', '', '', '');
65
+ cmdInputCollectorRunSpecificFuzzer();
66
+ println('CMD end: Run Fuzzer');
67
+ })
68
+ );
69
+
70
+ context.subscriptions.push(
71
+ vscode.commands.registerCommand('oss-fuzz.ListFuzzers', async () => {
72
+ println('CMD start: ListFuzzers');
73
+ await listFuzzersHandler();
74
+ println('CMD end: ListFuzzers');
75
+ })
76
+ );
77
+
78
+ context.subscriptions.push(
79
+ vscode.commands.registerCommand('oss-fuzz.SetOSSFuzzPath', async () => {
80
+ println('CMD start: SetOSSFuzzPath');
81
+ await setOssFuzzPath();
82
+ println('CMD end: SetOSSFuzzPath');
83
+ })
84
+ );
85
+
86
+ context.subscriptions.push(
87
+ vscode.commands.registerCommand('oss-fuzz.GetCodeCoverage', async () => {
88
+ println('CMD start: GetCodeCoverage');
89
+ await displayCodeCoverageFromOssFuzz(context);
90
+ println('CMD end: GetCodeCoverage');
91
+ })
92
+ );
93
+
94
+ context.subscriptions.push(
95
+ vscode.commands.registerCommand('oss-fuzz.ClearCodeCoverage', async () => {
96
+ println('CMD start: ClearCodeCoverage');
97
+ await clearCoverage();
98
+ println('CMD end: ClearCodeCoverage');
99
+ })
100
+ );
101
+
102
+ context.subscriptions.push(
103
+ vscode.commands.registerCommand('oss-fuzz.CreateOSSFuzzSetup', async () => {
104
+ println('CMD start: CreateOSSFuzzSetup');
105
+ await createOssFuzzSetup();
106
+ println('CMD end: CreateOSSFuzzSetup');
107
+ })
108
+ );
109
+
110
+ context.subscriptions.push(
111
+ vscode.commands.registerCommand('oss-fuzz.WSBuildFuzzers', async () => {
112
+ println('CMD start: WSBuildFuzzers3');
113
+ await cmdInputCollectorBuildFuzzersFromWorkspace();
114
+ println('CMD end: WSBuildFuzzers4');
115
+ })
116
+ );
117
+
118
+ context.subscriptions.push(
119
+ vscode.commands.registerCommand('oss-fuzz.SetupCIFuzz', async () => {
120
+ println('CMD start: SetupCIFuzz');
121
+ await setupCIFuzzHandler();
122
+ println('CMD end: SetupCIFuzz');
123
+ })
124
+ );
125
+
126
+ context.subscriptions.push(
127
+ vscode.commands.registerCommand('oss-fuzz.testFuzzer', async () => {
128
+ println('CMD start: testFuzzer');
129
+ await cmdInputCollectorTestFuzzer();
130
+ println('CMD end: testFuzzer');
131
+ })
132
+ );
133
+
134
+ context.subscriptions.push(
135
+ vscode.commands.registerCommand('oss-fuzz.testCodeCoverage', async () => {
136
+ println('CMD start: testCodeCoverage');
137
+ await runEndToEndAndGetCoverage(context);
138
+ println('CMD end: testCodeCoverage');
139
+ })
140
+ );
141
+
142
+ context.subscriptions.push(
143
+ vscode.commands.registerCommand('oss-fuzz.Reproduce', async () => {
144
+ println('CMD start: Reproduce');
145
+ await cmdInputCollectorReproduceTestcase();
146
+ println('CMD end: Reproduce');
147
+ })
148
+ );
149
+
150
+ context.subscriptions.push(
151
+ vscode.commands.registerCommand('oss-fuzz.Redo', async () => {
152
+ println('CMD start: Re');
153
+ await cmdDispatcherRe();
154
+ println('CMD end: Re');
155
+ })
156
+ );
157
+
158
+ context.subscriptions.push(
159
+ vscode.commands.registerCommand('oss-fuzz.Template', async () => {
160
+ println('CMD start: remplate');
161
+ await cmdDispatcherTemplate(context);
162
+ println('CMD end: template');
163
+ })
164
+ );
165
+
166
+ context.subscriptions.push(
167
+ vscode.commands.registerCommand(
168
+ 'oss-fuzz.GenerateClusterfuzzLite',
169
+ async () => {
170
+ println('CMD start: GenerateClusterfuzzLite');
171
+ await cmdDispatcherGenerateClusterfuzzLite(context);
172
+ println('CMD end: GenerateClusterfuzzLite');
173
+ }
174
+ )
175
+ );
176
+
177
+ context.subscriptions.push(
178
+ vscode.commands.registerCommand(
179
+ 'oss-fuzz.WSBuildFuzzersCFLite',
180
+ async () => {
181
+ println('CMD start: WSBuildFuzzersCFLite');
182
+ await cmdInputCollectorBuildFuzzersFromWorkspaceCFLite();
183
+ println('CMD end: WSBuildFuzzersCFLite');
184
+ }
185
+ )
186
+ );
187
+
188
+ context.subscriptions.push(
189
+ vscode.commands.registerCommand('oss-fuzz.testFuzzerCFLite', async () => {
190
+ println('CMD start: testFuzzerCFLite');
191
+ await cmdInputCollectorTestFuzzerCFLite();
192
+ println('CMD end: testFuzzerCFLite');
193
+ })
194
+ );
195
+
196
+ context.subscriptions.push(
197
+ vscode.commands.registerCommand(
198
+ 'oss-fuzz.setupFuzzIntrospector',
199
+ async () => {
200
+ println('CMD start: setup FI');
201
+ await setUpFuzzIntrospectorHandler();
202
+ }
203
+ )
204
+ );
205
+
206
+ context.subscriptions.push(
207
+ vscode.commands.registerCommand(
208
+ 'oss-fuzz.runFuzzIntrospector',
209
+ async () => {
210
+ println('CMD start: run Fuzz Introspector');
211
+ await runFuzzIntrospectorHandler();
212
+ }
213
+ )
214
+ );
215
+
216
+ context.subscriptions.push(
217
+ vscode.commands.registerCommand('oss-fuzz.GetOptimalTargets', async () => {
218
+ println('CMD start: run GetOptimalTargets');
219
+ await runGetOptimalTargetsHandler();
220
+ })
221
+ );
222
+ }
223
+
224
+ // This method is called when your extension is deactivated
225
+ export function deactivate() {
226
+ println('Deactivating the extension');
227
+ }