Add files using upload-large-folder tool
Browse files- local-test-zookeeper-full-01/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc +0 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/__pycache__/templates.cpython-312.pyc +0 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/ci/build_test.py +124 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/ci/requirements.txt +9 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/cifuzz.ts +70 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commandUtils.ts +17 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts +80 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdCreateOSSFuzzSetup.ts +28 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdDispatcherGenerateClusterfuzzLite.ts +38 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdRedo.ts +35 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts +167 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFI.ts +24 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetOSSFuzzPath.ts +59 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupCIFuzz.ts +87 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupFI.ts +24 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts +53 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdTemplate.ts +357 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzer.ts +90 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/logger.ts +31 -0
- local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/utils.ts +306 -0
local-test-zookeeper-full-01/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc
ADDED
|
Binary file (802 Bytes). View file
|
|
|
local-test-zookeeper-full-01/fuzz-tooling/infra/__pycache__/templates.cpython-312.pyc
ADDED
|
Binary file (3.04 kB). View file
|
|
|
local-test-zookeeper-full-01/fuzz-tooling/infra/ci/build_test.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
################################################################################
|
| 16 |
+
"""Tests for build.py"""
|
| 17 |
+
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
import unittest
|
| 21 |
+
from unittest import mock
|
| 22 |
+
|
| 23 |
+
# pylint: disable=wrong-import-position
|
| 24 |
+
INFRA_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 25 |
+
sys.path.append(INFRA_DIR)
|
| 26 |
+
|
| 27 |
+
from ci import build
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def patch_environ(testcase_obj):
|
| 31 |
+
"""Patch environment."""
|
| 32 |
+
env = {}
|
| 33 |
+
patcher = mock.patch.dict(os.environ, env)
|
| 34 |
+
testcase_obj.addCleanup(patcher.stop)
|
| 35 |
+
patcher.start()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _set_coverage_build():
|
| 39 |
+
"""Set the right environment variables for a coverage build."""
|
| 40 |
+
os.environ['SANITIZER'] = 'coverage'
|
| 41 |
+
os.environ['ENGINE'] = 'libfuzzer'
|
| 42 |
+
os.environ['ARCHITECTURE'] = 'x86_64'
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class TestShouldBuild(unittest.TestCase):
|
| 46 |
+
"""Tests that should_build() works as intended."""
|
| 47 |
+
|
| 48 |
+
def setUp(self):
|
| 49 |
+
patch_environ(self)
|
| 50 |
+
|
| 51 |
+
def test_none_engine_coverage_build(self):
|
| 52 |
+
"""Tests that should_build returns False for a coverage build of a
|
| 53 |
+
project that specifies 'none' for fuzzing_engines."""
|
| 54 |
+
_set_coverage_build()
|
| 55 |
+
project_yaml = {
|
| 56 |
+
'language': 'c++',
|
| 57 |
+
'fuzzing_engines': ['none'],
|
| 58 |
+
'sanitizers': ['address']
|
| 59 |
+
}
|
| 60 |
+
self.assertFalse(build.should_build(project_yaml))
|
| 61 |
+
|
| 62 |
+
def test_unspecified_engines_coverage_build(self):
|
| 63 |
+
"""Tests that should_build returns True for a coverage build of a
|
| 64 |
+
project that doesn't specify fuzzing_engines."""
|
| 65 |
+
_set_coverage_build()
|
| 66 |
+
project_yaml = {'language': 'c++'}
|
| 67 |
+
self.assertTrue(build.should_build(project_yaml))
|
| 68 |
+
|
| 69 |
+
def test_libfuzzer_coverage_build(self):
|
| 70 |
+
"""Tests that should_build returns True for coverage build of a project
|
| 71 |
+
specifying 'libfuzzer' for fuzzing_engines."""
|
| 72 |
+
_set_coverage_build()
|
| 73 |
+
project_yaml = {
|
| 74 |
+
'language': 'c++',
|
| 75 |
+
'fuzzing_engines': ['libfuzzer'],
|
| 76 |
+
'sanitizers': ['address']
|
| 77 |
+
}
|
| 78 |
+
self.assertTrue(build.should_build(project_yaml))
|
| 79 |
+
|
| 80 |
+
def test_go_coverage_build(self):
|
| 81 |
+
"""Tests that should_build returns True for coverage build of a project
|
| 82 |
+
specifying 'libfuzzer' for fuzzing_engines."""
|
| 83 |
+
_set_coverage_build()
|
| 84 |
+
project_yaml = {'language': 'go'}
|
| 85 |
+
self.assertTrue(build.should_build(project_yaml))
|
| 86 |
+
|
| 87 |
+
def test_engine_project_none_build(self):
|
| 88 |
+
"""Tests that should_build returns False for an engine: 'none' build when
|
| 89 |
+
the project doesn't specify engines."""
|
| 90 |
+
os.environ['SANITIZER'] = 'address'
|
| 91 |
+
os.environ['ENGINE'] = 'none'
|
| 92 |
+
os.environ['ARCHITECTURE'] = 'x86_64'
|
| 93 |
+
project_yaml = {
|
| 94 |
+
'language': 'c++',
|
| 95 |
+
'fuzzing_engines': ['libfuzzer'],
|
| 96 |
+
'sanitizers': ['address']
|
| 97 |
+
}
|
| 98 |
+
self.assertFalse(build.should_build(project_yaml))
|
| 99 |
+
|
| 100 |
+
def test_centipede_none_build(self):
|
| 101 |
+
"""Tests that should_build returns True for none sanitizer build of a
|
| 102 |
+
project specifying 'centipede' for fuzzing_engines."""
|
| 103 |
+
os.environ['SANITIZER'] = 'none'
|
| 104 |
+
os.environ['ENGINE'] = 'centipede'
|
| 105 |
+
os.environ['ARCHITECTURE'] = 'x86_64'
|
| 106 |
+
project_yaml = {
|
| 107 |
+
'language': 'c++',
|
| 108 |
+
'fuzzing_engines': ['centipede'],
|
| 109 |
+
'sanitizers': ['none']
|
| 110 |
+
}
|
| 111 |
+
self.assertTrue(build.should_build(project_yaml))
|
| 112 |
+
|
| 113 |
+
def test_centipede_address_build(self):
|
| 114 |
+
"""Tests that should_build returns True for address sanitizer build of a
|
| 115 |
+
project specifying 'centipede' for fuzzing_engines."""
|
| 116 |
+
os.environ['SANITIZER'] = 'address'
|
| 117 |
+
os.environ['ENGINE'] = 'centipede'
|
| 118 |
+
os.environ['ARCHITECTURE'] = 'x86_64'
|
| 119 |
+
project_yaml = {
|
| 120 |
+
'language': 'c++',
|
| 121 |
+
'fuzzing_engines': ['centipede'],
|
| 122 |
+
'sanitizers': ['address']
|
| 123 |
+
}
|
| 124 |
+
self.assertTrue(build.should_build(project_yaml))
|
local-test-zookeeper-full-01/fuzz-tooling/infra/ci/requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Requirements for submitting code changes to infra/ (needed by presubmit.py).
|
| 2 |
+
parameterized==0.7.4
|
| 3 |
+
pyfakefs==4.5.6
|
| 4 |
+
pylint==2.5.3
|
| 5 |
+
pytest==7.1.2
|
| 6 |
+
pytest-xdist==2.5.0
|
| 7 |
+
PyYAML==6.0
|
| 8 |
+
requests==2.31.0
|
| 9 |
+
yapf==0.32.0
|
local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/cifuzz.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {println} from './logger';
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Creates a CIFuzz template
|
| 21 |
+
* @param language
|
| 22 |
+
* @param projectName
|
| 23 |
+
* @param secondToRun
|
| 24 |
+
* @returns
|
| 25 |
+
*/
|
| 26 |
+
export function cifuzzGenerator(
|
| 27 |
+
language: string,
|
| 28 |
+
projectName: string,
|
| 29 |
+
secondToRun: Number
|
| 30 |
+
) {
|
| 31 |
+
println('Exporting cifuzz logic ' + language);
|
| 32 |
+
|
| 33 |
+
const cifuzzTemplate = `name: CIFuzz
|
| 34 |
+
on: [pull_request]
|
| 35 |
+
permissions: {}
|
| 36 |
+
jobs:
|
| 37 |
+
Fuzzing:
|
| 38 |
+
runs-on: ubuntu-latest
|
| 39 |
+
permissions:
|
| 40 |
+
security-events: write
|
| 41 |
+
steps:
|
| 42 |
+
- name: Build Fuzzers
|
| 43 |
+
id: build
|
| 44 |
+
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
| 45 |
+
with:
|
| 46 |
+
oss-fuzz-project-name: '${projectName}'
|
| 47 |
+
language: ${language}
|
| 48 |
+
- name: Run Fuzzers
|
| 49 |
+
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
| 50 |
+
with:
|
| 51 |
+
oss-fuzz-project-name: '${projectName}'
|
| 52 |
+
language: ${language}
|
| 53 |
+
fuzz-seconds: ${secondToRun}
|
| 54 |
+
output-sarif: true
|
| 55 |
+
- name: Upload Crash
|
| 56 |
+
uses: actions/upload-artifact@v3
|
| 57 |
+
if: failure() && steps.build.outcome == 'success'
|
| 58 |
+
with:
|
| 59 |
+
name: artifacts
|
| 60 |
+
path: ./out/artifacts
|
| 61 |
+
- name: Upload Sarif
|
| 62 |
+
if: always() && steps.build.outcome == 'success'
|
| 63 |
+
uses: github/codeql-action/upload-sarif@v2
|
| 64 |
+
with:
|
| 65 |
+
# Path to SARIF file relative to the root of the repository
|
| 66 |
+
sarif_file: cifuzz-sarif/results.sarif
|
| 67 |
+
checkout_path: cifuzz-sarif`;
|
| 68 |
+
|
| 69 |
+
return cifuzzTemplate;
|
| 70 |
+
}
|
local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commandUtils.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
export const commandHistory: any[] = [];
|
local-test-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdCreateOSSFuzzSetup.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {setupProjectInitialFiles} from '../projectIntegrationHelper';
|
| 18 |
+
import {setStatusText} from '../utils';
|
| 19 |
+
|
| 20 |
+
export async function createOssFuzzSetup() {
|
| 21 |
+
await setStatusText('Creating OSS-Fuzz setup: starting');
|
| 22 |
+
const res = await setupProjectInitialFiles(false);
|
| 23 |
+
if (res) {
|
| 24 |
+
await setStatusText('Creating OSS-Fuzz setup: finished');
|
| 25 |
+
} else {
|
| 26 |
+
await setStatusText('Creating OSS-Fuzz setup: failed');
|
| 27 |
+
}
|
| 28 |
+
}
|
local-test-zookeeper-full-01/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-zookeeper-full-01/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-zookeeper-full-01/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-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetOSSFuzzPath.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {println} from '../logger';
|
| 20 |
+
import {extensionConfig} from '../config';
|
| 21 |
+
|
| 22 |
+
// Set the oss-fuzz path.
|
| 23 |
+
export async function setOssFuzzPath() {
|
| 24 |
+
println('Setting path');
|
| 25 |
+
const newOssFuzzPath = await vscode.window.showInputBox({
|
| 26 |
+
value: '',
|
| 27 |
+
placeHolder: 'Type path',
|
| 28 |
+
});
|
| 29 |
+
if (!newOssFuzzPath) {
|
| 30 |
+
println('Failed getting path');
|
| 31 |
+
return;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const fpathh = vscode.Uri.file(newOssFuzzPath);
|
| 35 |
+
let isValid = false;
|
| 36 |
+
try {
|
| 37 |
+
if (await vscode.workspace.fs.readDirectory(fpathh)) {
|
| 38 |
+
println('Is a directory');
|
| 39 |
+
const helperPathURI = vscode.Uri.file(
|
| 40 |
+
newOssFuzzPath + '/infra/helper.py'
|
| 41 |
+
);
|
| 42 |
+
if (await vscode.workspace.fs.readFile(helperPathURI)) {
|
| 43 |
+
println('Found helper file');
|
| 44 |
+
isValid = true;
|
| 45 |
+
}
|
| 46 |
+
isValid = true;
|
| 47 |
+
} else {
|
| 48 |
+
isValid = false;
|
| 49 |
+
}
|
| 50 |
+
} catch {
|
| 51 |
+
isValid = false;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if (isValid) {
|
| 55 |
+
extensionConfig.ossFuzzPepositoryWorkPath = newOssFuzzPath;
|
| 56 |
+
} else {
|
| 57 |
+
println('Not setting OSS-Fuzz path');
|
| 58 |
+
}
|
| 59 |
+
}
|
local-test-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupFI.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 {setUpFuzzIntrospector} from '../fuzzIntrospectorHelper';
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Function for setting up Fuzz Introspector by way of a Python virtual env.
|
| 21 |
+
*/
|
| 22 |
+
export async function setUpFuzzIntrospectorHandler() {
|
| 23 |
+
setUpFuzzIntrospector();
|
| 24 |
+
}
|
local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {println} from '../logger';
|
| 18 |
+
import {extensionConfig} from '../config';
|
| 19 |
+
import {isPathValidOssFuzzPath} from '../ossfuzzWrappers';
|
| 20 |
+
import {systemSync} from '../utils';
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Function for setting up oss-fuzz. This clones the relevant directory
|
| 24 |
+
* and sets the oss-fuzz variable accordingly.
|
| 25 |
+
*/
|
| 26 |
+
export async function setUpOssFuzzHandler() {
|
| 27 |
+
println('Setting up oss-fuzz in /tmp/');
|
| 28 |
+
|
| 29 |
+
// First check if we already have an OSS-Fuzz path
|
| 30 |
+
const tmpOssFuzzRepositoryPath = '/tmp/oss-fuzz';
|
| 31 |
+
|
| 32 |
+
if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
|
| 33 |
+
println('OSS-Fuzz already exists in /tmp/oss-fuzz');
|
| 34 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const cmdToExec = 'git';
|
| 39 |
+
const args: Array<string> = [
|
| 40 |
+
'clone',
|
| 41 |
+
'https://github.com/google/oss-fuzz',
|
| 42 |
+
tmpOssFuzzRepositoryPath,
|
| 43 |
+
];
|
| 44 |
+
const [res, output] = await systemSync(cmdToExec, args);
|
| 45 |
+
if (res === false) {
|
| 46 |
+
println('Failed to clone oss-fuzz');
|
| 47 |
+
println(output);
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
println('Finished cloning oss-fuzz');
|
| 51 |
+
|
| 52 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 53 |
+
}
|
local-test-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzer.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {runFuzzerHandler, buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 20 |
+
import {setStatusText} from '../utils';
|
| 21 |
+
import {commandHistory} from '../commandUtils';
|
| 22 |
+
import {extensionConfig} from '../config';
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Does an end-to-end test of a project/fuzzer. This is done by
|
| 26 |
+
* first building the project and then running the fuzzer.
|
| 27 |
+
* @param context
|
| 28 |
+
* @returns
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
export async function cmdInputCollectorTestFuzzer() {
|
| 32 |
+
setStatusText('Testing specific fuzzer: getting input');
|
| 33 |
+
// Get the project name and fuzzer name to test.
|
| 34 |
+
const ossFuzzProjectNameInput = await vscode.window.showInputBox({
|
| 35 |
+
value: '',
|
| 36 |
+
placeHolder: 'The OSS-Fuzz project name',
|
| 37 |
+
});
|
| 38 |
+
if (!ossFuzzProjectNameInput) {
|
| 39 |
+
println('Did not get a ossFuzzTargetProject');
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
println('Project name: ' + ossFuzzProjectNameInput);
|
| 43 |
+
|
| 44 |
+
// Get the fuzzer to run
|
| 45 |
+
const fuzzerNameInput = await vscode.window.showInputBox({
|
| 46 |
+
value: '',
|
| 47 |
+
placeHolder: 'Type a fuzzer name',
|
| 48 |
+
});
|
| 49 |
+
if (!fuzzerNameInput) {
|
| 50 |
+
println('Failed to get fuzzer name');
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Create the args object for the dispatcher
|
| 55 |
+
const args = new Object({
|
| 56 |
+
projectName: ossFuzzProjectNameInput.toString(),
|
| 57 |
+
fuzzerName: fuzzerNameInput.toString(),
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
// Create a dispatcher object.
|
| 61 |
+
const commandObject = new Object({
|
| 62 |
+
commandType: 'oss-fuzz.TestFuzzer',
|
| 63 |
+
Arguments: args,
|
| 64 |
+
dispatcherFunc: cmdDispatchTestFuzzerHandler,
|
| 65 |
+
});
|
| 66 |
+
commandHistory.push(commandObject);
|
| 67 |
+
|
| 68 |
+
await cmdDispatchTestFuzzerHandler(args);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
async function cmdDispatchTestFuzzerHandler(args: any) {
|
| 72 |
+
// Build the project
|
| 73 |
+
setStatusText('Test specific fuzzer: building fuzzers in workspace');
|
| 74 |
+
if (!(await buildFuzzersFromWorkspace(args.projectName, '', false))) {
|
| 75 |
+
println('Build projects');
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Run the fuzzer for 10 seconds
|
| 80 |
+
println('Running fuzzer');
|
| 81 |
+
setStatusText('Test specific fuzzer: running fuzzer ' + args.fuzzerName);
|
| 82 |
+
await runFuzzerHandler(
|
| 83 |
+
args.projectName,
|
| 84 |
+
args.fuzzerName,
|
| 85 |
+
extensionConfig.numberOfSecondsForTestRuns.toString(),
|
| 86 |
+
''
|
| 87 |
+
);
|
| 88 |
+
setStatusText('Test specific fuzzer: test completed of ' + args.fuzzerName);
|
| 89 |
+
return;
|
| 90 |
+
}
|
local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/logger.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
export const vscodeOutputChannel =
|
| 19 |
+
vscode.window.createOutputChannel('oss-fuzz');
|
| 20 |
+
|
| 21 |
+
export function println(line: string) {
|
| 22 |
+
vscodeOutputChannel.appendLine(line);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export function printRaw(line: string) {
|
| 26 |
+
vscodeOutputChannel.append(line);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export function debugPrintln(line: string) {
|
| 30 |
+
console.log(line);
|
| 31 |
+
}
|
local-test-zookeeper-full-01/fuzz-tooling/tools/vscode-extension/src/utils.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {extensionConfig} from './config';
|
| 19 |
+
import {getApi, FileDownloader} from '@microsoft/vscode-file-downloader-api';
|
| 20 |
+
|
| 21 |
+
const fs = require('fs');
|
| 22 |
+
const {spawn} = require('node:child_process');
|
| 23 |
+
const statusBarComp = vscode.window.createStatusBarItem(
|
| 24 |
+
vscode.StatusBarAlignment.Right,
|
| 25 |
+
100
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
import {println, printRaw, debugPrintln} from './logger';
|
| 29 |
+
|
| 30 |
+
export async function setStatusText(statusText: string) {
|
| 31 |
+
//let myStatusBarItem: vscode.StatusBarItem;
|
| 32 |
+
statusBarComp.text = '$(megaphone) OSS-Fuzz: ' + statusText;
|
| 33 |
+
statusBarComp.show();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export async function downloadRemoteURL(
|
| 37 |
+
urlString: string,
|
| 38 |
+
targetFile: string,
|
| 39 |
+
context: vscode.ExtensionContext
|
| 40 |
+
) {
|
| 41 |
+
const fileDownloader: FileDownloader = await getApi();
|
| 42 |
+
println('URL: ' + urlString);
|
| 43 |
+
let codeCoverageFile: vscode.Uri;
|
| 44 |
+
try {
|
| 45 |
+
codeCoverageFile = await fileDownloader.downloadFile(
|
| 46 |
+
vscode.Uri.parse(urlString),
|
| 47 |
+
targetFile,
|
| 48 |
+
context
|
| 49 |
+
);
|
| 50 |
+
} catch (err) {
|
| 51 |
+
println('Could not get the coverage summary file');
|
| 52 |
+
return false;
|
| 53 |
+
}
|
| 54 |
+
return codeCoverageFile;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
export async function getLocalOutBuildDir(projectName: string) {
|
| 58 |
+
const summaryCovPath =
|
| 59 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/build/out/' + projectName;
|
| 60 |
+
return summaryCovPath;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
export async function getOSSFuzzCloudURL(projectName: string) {
|
| 64 |
+
const currentDate = new Date();
|
| 65 |
+
const yesterday = new Date(currentDate);
|
| 66 |
+
yesterday.setDate(yesterday.getDate() - 1);
|
| 67 |
+
|
| 68 |
+
const day = yesterday.getDate();
|
| 69 |
+
const month = yesterday.getMonth();
|
| 70 |
+
const year = yesterday.getFullYear();
|
| 71 |
+
|
| 72 |
+
let urlString =
|
| 73 |
+
'https://storage.googleapis.com/oss-fuzz-coverage/' +
|
| 74 |
+
projectName +
|
| 75 |
+
'/reports/' +
|
| 76 |
+
year.toString();
|
| 77 |
+
|
| 78 |
+
if (month < 10) {
|
| 79 |
+
urlString += '0';
|
| 80 |
+
}
|
| 81 |
+
urlString += month.toString();
|
| 82 |
+
if (day < 10) {
|
| 83 |
+
urlString += '0';
|
| 84 |
+
}
|
| 85 |
+
urlString += day.toString();
|
| 86 |
+
|
| 87 |
+
return urlString;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Checks if the current workspace has a generated OSS-Fuzz folder. This is the
|
| 92 |
+
* generated folder from our auto-generation capabilities.
|
| 93 |
+
*
|
| 94 |
+
* @returns boolean
|
| 95 |
+
*/
|
| 96 |
+
export async function hasOssFuzzInWorkspace() {
|
| 97 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 98 |
+
|
| 99 |
+
if (!workspaceFolder) {
|
| 100 |
+
return false;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Identify if the workspace folder has a OSS-Fuzz set up.
|
| 104 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 105 |
+
const ossfuzzDockerFilepath = vscode.Uri.file(wsPath + '/OSS-Fuzz/');
|
| 106 |
+
try {
|
| 107 |
+
if (await vscode.workspace.fs.readDirectory(ossfuzzDockerFilepath)) {
|
| 108 |
+
for (const [name, type] of await vscode.workspace.fs.readDirectory(
|
| 109 |
+
ossfuzzDockerFilepath
|
| 110 |
+
)) {
|
| 111 |
+
// If it's a directory then we know we have the project set up in there.
|
| 112 |
+
if (type === 2) {
|
| 113 |
+
// We assume this is the project folder for now.
|
| 114 |
+
println('Found the relevant directory: ' + name);
|
| 115 |
+
return true;
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
} catch {
|
| 120 |
+
/* empty */
|
| 121 |
+
}
|
| 122 |
+
return false;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Gets the project name of the integrated OSS-Fuzz project.
|
| 127 |
+
* @returns string
|
| 128 |
+
*/
|
| 129 |
+
export async function getOssFuzzWorkspaceProjectName() {
|
| 130 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 131 |
+
if (!workspaceFolder) {
|
| 132 |
+
return 'N/A';
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// Identify if the workspace folder has a OSS-Fuzz set up.
|
| 136 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 137 |
+
const ossfuzzDockerFilepath = vscode.Uri.file(wsPath + '/OSS-Fuzz/');
|
| 138 |
+
try {
|
| 139 |
+
if (await vscode.workspace.fs.readDirectory(ossfuzzDockerFilepath)) {
|
| 140 |
+
for (const [name, type] of await vscode.workspace.fs.readDirectory(
|
| 141 |
+
ossfuzzDockerFilepath
|
| 142 |
+
)) {
|
| 143 |
+
if (type === 2) {
|
| 144 |
+
// println('Is a directory');
|
| 145 |
+
// We assume this is the project folder for now.
|
| 146 |
+
return name;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
} catch {
|
| 151 |
+
/* empty */
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
return 'N/A';
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Lists the fuzzers available in the OSS-Fuzz build project.
|
| 159 |
+
*
|
| 160 |
+
* @param projectName
|
| 161 |
+
* @param ossFuzzRepositoryPath
|
| 162 |
+
* @returns
|
| 163 |
+
*/
|
| 164 |
+
export async function listFuzzersForProject(
|
| 165 |
+
projectName: string,
|
| 166 |
+
ossFuzzRepositoryPath: string
|
| 167 |
+
) {
|
| 168 |
+
const projectOssFuzzBuildPath = vscode.Uri.file(
|
| 169 |
+
ossFuzzRepositoryPath + '/build/out/' + projectName
|
| 170 |
+
);
|
| 171 |
+
const fuzzersInProject: Array<string> = [];
|
| 172 |
+
for (const [name, type] of await vscode.workspace.fs.readDirectory(
|
| 173 |
+
projectOssFuzzBuildPath
|
| 174 |
+
)) {
|
| 175 |
+
// Is it a file?
|
| 176 |
+
if (type === 1) {
|
| 177 |
+
const filepath =
|
| 178 |
+
ossFuzzRepositoryPath + '/build/out/' + projectName + '/' + name;
|
| 179 |
+
const binary = fs.readFileSync(filepath);
|
| 180 |
+
|
| 181 |
+
// Check if fuzzer entrypoint exists in file. This is similar to how OSS-Fuzz
|
| 182 |
+
// checks whether a file is fuzzer or not.
|
| 183 |
+
if (binary.lastIndexOf('LLVMFuzzerTestOneInput') !== -1) {
|
| 184 |
+
fuzzersInProject.push(name);
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
println('Successfully build the project.');
|
| 189 |
+
println('The fuzzers in project');
|
| 190 |
+
for (const fuzzName of fuzzersInProject) {
|
| 191 |
+
println(fuzzName);
|
| 192 |
+
}
|
| 193 |
+
return fuzzersInProject;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* Helper functions for identifying the primary programming language of the workspace.
|
| 198 |
+
*
|
| 199 |
+
* This is achieved by identifying the suffix of files and then sorting
|
| 200 |
+
* based on those with most of a given language supported by OSS-Fuzz.
|
| 201 |
+
*
|
| 202 |
+
* @returns
|
| 203 |
+
*/
|
| 204 |
+
export async function determineWorkspaceLanguage() {
|
| 205 |
+
const pythonFiles = await vscode.workspace.findFiles('**/*.py');
|
| 206 |
+
const cppFiles = await vscode.workspace.findFiles('**/*.c++');
|
| 207 |
+
const cfiles = await vscode.workspace.findFiles('**/*.c');
|
| 208 |
+
const rustFiles = await vscode.workspace.findFiles('**/*.rust');
|
| 209 |
+
const golangFiles = await vscode.workspace.findFiles('**/*.go');
|
| 210 |
+
|
| 211 |
+
println('Number of python files: ' + pythonFiles.length);
|
| 212 |
+
println('Number of C++ files: ' + cppFiles.length);
|
| 213 |
+
println('Number of C files: ' + cfiles.length);
|
| 214 |
+
println('Number of rustFiles files: ' + rustFiles.length);
|
| 215 |
+
println('Number of golangFiles files: ' + golangFiles.length);
|
| 216 |
+
|
| 217 |
+
const maxCount = Math.max(
|
| 218 |
+
pythonFiles.length,
|
| 219 |
+
cppFiles.length,
|
| 220 |
+
cfiles.length,
|
| 221 |
+
rustFiles.length,
|
| 222 |
+
golangFiles.length
|
| 223 |
+
);
|
| 224 |
+
let target = '';
|
| 225 |
+
if (maxCount === pythonFiles.length) {
|
| 226 |
+
target = 'python';
|
| 227 |
+
} else if (maxCount === cppFiles.length) {
|
| 228 |
+
target = 'c++';
|
| 229 |
+
} else if (maxCount === cfiles.length) {
|
| 230 |
+
target = 'c';
|
| 231 |
+
} else if (maxCount === rustFiles.length) {
|
| 232 |
+
target = 'rust';
|
| 233 |
+
} else if (maxCount === golangFiles.length) {
|
| 234 |
+
target = 'golang';
|
| 235 |
+
} else {
|
| 236 |
+
target = 'not implemented';
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
println('Target language: ' + target);
|
| 240 |
+
return target;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
/**
|
| 244 |
+
* Helper method to execute commands on the system.
|
| 245 |
+
*/
|
| 246 |
+
export async function systemSync(cmd: string, args: Array<string | undefined>) {
|
| 247 |
+
debugPrintln('Running command');
|
| 248 |
+
debugPrintln(cmd);
|
| 249 |
+
debugPrintln(args.toString());
|
| 250 |
+
debugPrintln('<<<<<<<<<<<<');
|
| 251 |
+
|
| 252 |
+
// Launch the command
|
| 253 |
+
const command = spawn(cmd, args);
|
| 254 |
+
|
| 255 |
+
// Callbacks for output events, to capture stdout and stderr live.
|
| 256 |
+
command.stdout.on('data', (x: {toString: () => string}) => {
|
| 257 |
+
printRaw(x.toString());
|
| 258 |
+
});
|
| 259 |
+
command.stderr.on('data', (x: {toString: () => string}) => {
|
| 260 |
+
printRaw(x.toString());
|
| 261 |
+
});
|
| 262 |
+
|
| 263 |
+
// Monitor for child exit.
|
| 264 |
+
let hasChildExited = 0;
|
| 265 |
+
let childExitCode = 0;
|
| 266 |
+
command.on('exit', (code: any, signal: any) => {
|
| 267 |
+
// println('child process exited with ' + `code ${code} and signal ${signal}`);
|
| 268 |
+
childExitCode = code;
|
| 269 |
+
hasChildExited = 1;
|
| 270 |
+
});
|
| 271 |
+
|
| 272 |
+
// Block until the child process has exited.
|
| 273 |
+
const snooze = (ms: number) =>
|
| 274 |
+
new Promise(resolve => setTimeout(resolve, ms));
|
| 275 |
+
|
| 276 |
+
let idx = 0;
|
| 277 |
+
const maxSeconds = 1800;
|
| 278 |
+
debugPrintln('Child exited: ' + hasChildExited);
|
| 279 |
+
|
| 280 |
+
// I think we can convert the following loop to a Promise wrapping the command
|
| 281 |
+
// exeuction. TODO(David).
|
| 282 |
+
while (hasChildExited === 0 && idx < maxSeconds) {
|
| 283 |
+
idx += 1;
|
| 284 |
+
await snooze(1000);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// Command execution is done, return appropriately if success/error.
|
| 288 |
+
if (childExitCode !== 0) {
|
| 289 |
+
println('Command execution errored');
|
| 290 |
+
return [false, command.toString()];
|
| 291 |
+
}
|
| 292 |
+
// println('Succes');
|
| 293 |
+
return [true, command.toString()];
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
export async function systemSyncLogIfFailure(
|
| 297 |
+
cmd: string,
|
| 298 |
+
args: Array<string | undefined>
|
| 299 |
+
): Promise<boolean> {
|
| 300 |
+
const [res, cmdMsg] = await systemSync(cmd, args);
|
| 301 |
+
if (res === false) {
|
| 302 |
+
println(cmdMsg);
|
| 303 |
+
return false;
|
| 304 |
+
}
|
| 305 |
+
return true;
|
| 306 |
+
}
|