Add files using upload-large-folder tool
Browse files- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/getting-started/new-project-guide/bazel.md +97 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/infra/ci/requirements.txt +9 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/.editorconfig +8 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/.gitignore +6 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/.prettierrc.js +18 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/cifuzz.ts +70 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commandUtils.ts +17 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdDisplayCoverage.ts +71 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdFIGetOptimalTargets.ts +21 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdListFuzzers.ts +42 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetOSSFuzzPath.ts +59 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupFI.ts +24 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts +53 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/config.ts +37 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/coverageHelper.ts +300 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/fuzzIntrospectorHelper.ts +117 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/logger.ts +31 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/ossfuzzWrappers.ts +385 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/projectIntegrationHelper.ts +761 -0
- local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/utils.ts +306 -0
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/docs/getting-started/new-project-guide/bazel.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
layout: default
|
| 3 |
+
title: Integrating a Bazel project
|
| 4 |
+
parent: Setting up a new project
|
| 5 |
+
grand_parent: Getting started
|
| 6 |
+
nav_order: 5
|
| 7 |
+
permalink: /getting-started/new-project-guide/bazel/
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Integrating a Bazel project
|
| 11 |
+
{: .no_toc}
|
| 12 |
+
|
| 13 |
+
- TOC
|
| 14 |
+
{:toc}
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## Bazel projects
|
| 18 |
+
|
| 19 |
+
The process of integrating a project using the [Bazel](https://bazel.build/)
|
| 20 |
+
build system with OSS-Fuzz is very similar to the general
|
| 21 |
+
[Setting up a new project]({{ site.baseurl }}/getting-started/new-project-guide/)
|
| 22 |
+
process. The key specifics of integrating a Bazel project are outlined below.
|
| 23 |
+
|
| 24 |
+
## Fuzzing support in Bazel
|
| 25 |
+
|
| 26 |
+
For Bazel-based projects, we recommend using the
|
| 27 |
+
[`rules_fuzzing`](https://github.com/bazelbuild/rules_fuzzing) extension library
|
| 28 |
+
for defining fuzz tests. `rules_fuzzing` provides support for building and running
|
| 29 |
+
fuzz tests under
|
| 30 |
+
[multiple sanitizer and fuzzing engine configurations][rules-fuzzing-usage].
|
| 31 |
+
It also supports specifying corpora and dictionaries as part of the fuzz test
|
| 32 |
+
definition.
|
| 33 |
+
|
| 34 |
+
The fuzzing rules provide out-of-the-box support for building and packaging fuzz
|
| 35 |
+
test artifacts in the OSS-Fuzz format. Each `//path/to:fuzz_test` fuzz test
|
| 36 |
+
target automatically has a `//path/to:fuzz_test_oss_fuzz` packaging target that
|
| 37 |
+
(a) builds the fuzz test using the instrumentation and engine library specified
|
| 38 |
+
in the OSS-Fuzz environment variables, and (b) generates an archive containing
|
| 39 |
+
the binary and its associated artifacts (corpus, dictionary, etc.). Moreover,
|
| 40 |
+
OSS-Fuzz provides a standard tool to automatically process these targets,
|
| 41 |
+
substantially simplifying the `build.sh` script (see below).
|
| 42 |
+
|
| 43 |
+
[rules-fuzzing-usage]: https://github.com/bazelbuild/rules_fuzzing#using-the-rules-in-your-project
|
| 44 |
+
|
| 45 |
+
## Project files
|
| 46 |
+
|
| 47 |
+
This section explains how to integrate the fuzz tests written using the
|
| 48 |
+
`rules_fuzzing` library with OSS-Fuzz. You can also see a complete example in the
|
| 49 |
+
[`bazel-rules-fuzzing-test`](https://github.com/google/oss-fuzz/tree/master/projects/bazel-rules-fuzzing-test)
|
| 50 |
+
project.
|
| 51 |
+
|
| 52 |
+
The structure of the project directory in the OSS-Fuzz repository does not
|
| 53 |
+
differ for Bazel-based projects. The project files have the following specific
|
| 54 |
+
aspects.
|
| 55 |
+
|
| 56 |
+
### project.yaml
|
| 57 |
+
|
| 58 |
+
Only C++ projects are currently supported.
|
| 59 |
+
|
| 60 |
+
Since the OSS-Fuzz target builds the fuzz test using the instrumentation and
|
| 61 |
+
engine specified in the OSS-Fuzz environment variables, all the engine and
|
| 62 |
+
sanitizer configurations supported in the `project.yaml` file are automatically
|
| 63 |
+
supported by the fuzzing rules.
|
| 64 |
+
|
| 65 |
+
### Dockerfile
|
| 66 |
+
|
| 67 |
+
There is no need to install Bazel in your Docker image. The OSS-Fuzz builder
|
| 68 |
+
image provides the `bazel` executable through the
|
| 69 |
+
[Bazelisk](https://github.com/bazelbuild/bazelisk) launcher, which will fetch
|
| 70 |
+
and use the latest Bazel release. If your project requires a particular Bazel
|
| 71 |
+
version, create a
|
| 72 |
+
[`.bazelversion`](https://docs.bazel.build/versions/master/updating-bazel.html)
|
| 73 |
+
file in your repository root with the desired version string.
|
| 74 |
+
|
| 75 |
+
### build.sh
|
| 76 |
+
|
| 77 |
+
Your `build.sh` script essentially needs to perform three steps: (1) selecting
|
| 78 |
+
which fuzz tests to build, (2) building their OSS-Fuzz package targets in the
|
| 79 |
+
right configuration, and (3) copying the build artifacts to the `${OUT}/`
|
| 80 |
+
destination.
|
| 81 |
+
|
| 82 |
+
OSS-Fuzz provides a
|
| 83 |
+
[`bazel_build_fuzz_tests`](https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/bazel_build_fuzz_tests)
|
| 84 |
+
tool that implements these steps in a standard way, so in most cases your
|
| 85 |
+
build script only needs to invoke this command with no arguments.
|
| 86 |
+
|
| 87 |
+
If necessary, the behavior of the tool can be customized through a set of
|
| 88 |
+
environment variables. The most common are:
|
| 89 |
+
|
| 90 |
+
* `BAZEL_EXTRA_BUILD_FLAGS` are extra build flags passed on the Bazel command
|
| 91 |
+
line.
|
| 92 |
+
* `BAZEL_FUZZ_TEST_TAG` and `BAZEL_FUZZ_TEST_EXCLUDE_TAG` can be overridden to
|
| 93 |
+
specify which target tags to use when determining what fuzz tests to include.
|
| 94 |
+
By default, the tool selects all the fuzz tests except for those tagged as
|
| 95 |
+
`"no-oss-fuzz"`.
|
| 96 |
+
* `BAZEL_FUZZ_TEST_QUERY` overrides the Bazel query the tool uses to identify
|
| 97 |
+
the fuzz tests to build, if the tag-based approach is not sufficient.
|
local-test-commons-compress-full-01-vuln_1/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-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/.editorconfig
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
root = true
|
| 2 |
+
|
| 3 |
+
[*]
|
| 4 |
+
indent_style = space
|
| 5 |
+
indent_size = 2
|
| 6 |
+
end_of_line = lf
|
| 7 |
+
charset = utf-8
|
| 8 |
+
insert_final_newline = true
|
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
out
|
| 2 |
+
build
|
| 3 |
+
dist
|
| 4 |
+
node_modules
|
| 5 |
+
.vscode-test/
|
| 6 |
+
*.vsix
|
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/.prettierrc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
module.exports = {
|
| 17 |
+
...require('gts/.prettierrc.json')
|
| 18 |
+
}
|
local-test-commons-compress-full-01-vuln_1/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-commons-compress-full-01-vuln_1/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-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdDisplayCoverage.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {loadCoverageIntoWorkspace} from '../coverageHelper';
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {getApi, FileDownloader} from '@microsoft/vscode-file-downloader-api';
|
| 21 |
+
|
| 22 |
+
/*
|
| 23 |
+
* Displays code coverage from OSS-Fuzz.
|
| 24 |
+
*
|
| 25 |
+
* Downloads a code coverage report from the OSS-Fuzz online storage, and then overlays
|
| 26 |
+
* the relevant source files with the coverage information.
|
| 27 |
+
*/
|
| 28 |
+
export async function displayCodeCoverageFromOssFuzz(
|
| 29 |
+
context: vscode.ExtensionContext
|
| 30 |
+
) {
|
| 31 |
+
const projectName = await vscode.window.showInputBox({
|
| 32 |
+
value: '',
|
| 33 |
+
placeHolder: "The project you'd like to get code coverage for.",
|
| 34 |
+
});
|
| 35 |
+
if (!projectName) {
|
| 36 |
+
return;
|
| 37 |
+
}
|
| 38 |
+
println('Getting code coverage for ' + projectName);
|
| 39 |
+
|
| 40 |
+
const fileDownloader: FileDownloader = await getApi();
|
| 41 |
+
|
| 42 |
+
const currentDate = new Date();
|
| 43 |
+
const yesterday = new Date(currentDate);
|
| 44 |
+
yesterday.setDate(yesterday.getDate() - 1);
|
| 45 |
+
|
| 46 |
+
const day = yesterday.getDate();
|
| 47 |
+
const month = yesterday.getMonth();
|
| 48 |
+
const year = yesterday.getFullYear();
|
| 49 |
+
|
| 50 |
+
try {
|
| 51 |
+
const codeCoverageFile: vscode.Uri = await fileDownloader.downloadFile(
|
| 52 |
+
vscode.Uri.parse(
|
| 53 |
+
'https://storage.googleapis.com/oss-fuzz-coverage/' +
|
| 54 |
+
projectName +
|
| 55 |
+
'/textcov_reports/' +
|
| 56 |
+
year.toString() +
|
| 57 |
+
month.toString() +
|
| 58 |
+
day.toString() +
|
| 59 |
+
'/all_cov.json'
|
| 60 |
+
),
|
| 61 |
+
'all_cov.json',
|
| 62 |
+
context
|
| 63 |
+
);
|
| 64 |
+
await loadCoverageIntoWorkspace(context, codeCoverageFile);
|
| 65 |
+
} catch (err) {
|
| 66 |
+
println(
|
| 67 |
+
'Could not get the URL. Currently, this feature is only supported for Python projects'
|
| 68 |
+
);
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
}
|
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdFIGetOptimalTargets.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2025 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 {getOptimalTargetsFromIntrospector} from '../fuzzIntrospectorHelper';
|
| 18 |
+
|
| 19 |
+
export async function runGetOptimalTargetsHandler() {
|
| 20 |
+
getOptimalTargetsFromIntrospector();
|
| 21 |
+
}
|
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/commands/cmdListFuzzers.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {listFuzzersForProject} from '../utils';
|
| 20 |
+
import {println} from '../logger';
|
| 21 |
+
import {extensionConfig} from '../config';
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* Lists all the fuzzers for a project.
|
| 25 |
+
*/
|
| 26 |
+
export async function listFuzzersHandler() {
|
| 27 |
+
// Lists all of the fuzzers from a project.
|
| 28 |
+
const projectName = await vscode.window.showInputBox({
|
| 29 |
+
value: '',
|
| 30 |
+
placeHolder: 'Type a project name',
|
| 31 |
+
});
|
| 32 |
+
if (!projectName) {
|
| 33 |
+
console.log('Failed to get project name');
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
println('Listing fuzzers for project ' + projectName);
|
| 37 |
+
|
| 38 |
+
await listFuzzersForProject(
|
| 39 |
+
projectName?.toString(),
|
| 40 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 41 |
+
);
|
| 42 |
+
}
|
local-test-commons-compress-full-01-vuln_1/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-commons-compress-full-01-vuln_1/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-commons-compress-full-01-vuln_1/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-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/config.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
export class ExtensionConfig {
|
| 20 |
+
/** Path to the repository that will be used. */
|
| 21 |
+
ossFuzzPepositoryWorkPath: string = '/tmp/oss-fuzz';
|
| 22 |
+
|
| 23 |
+
/** The directory where crash info is stored. */
|
| 24 |
+
crashesDirectory = process.env.HOME + '/oss-fuzz-crashes';
|
| 25 |
+
|
| 26 |
+
/** Number of seconds used for running quick test fuzzers */
|
| 27 |
+
numberOfSecondsForTestRuns = 20;
|
| 28 |
+
|
| 29 |
+
async printConfig() {
|
| 30 |
+
println('Config:');
|
| 31 |
+
println('- OSS-Fuzz repository path: ' + this.ossFuzzPepositoryWorkPath);
|
| 32 |
+
println('- Crashes directory: ' + this.crashesDirectory);
|
| 33 |
+
println('- numberOfSecondsForTestRuns: ' + this.numberOfSecondsForTestRuns);
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
export const extensionConfig = new ExtensionConfig();
|
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/coverageHelper.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 {Uri} from 'vscode';
|
| 19 |
+
import {println} from './logger';
|
| 20 |
+
import {
|
| 21 |
+
getOSSFuzzCloudURL,
|
| 22 |
+
getLocalOutBuildDir,
|
| 23 |
+
downloadRemoteURL,
|
| 24 |
+
} from './utils';
|
| 25 |
+
|
| 26 |
+
const path = require('path');
|
| 27 |
+
let isCodeCoverageEnabled = false;
|
| 28 |
+
|
| 29 |
+
// create a decorator type that we use to decorate small numbers
|
| 30 |
+
const codeCoveredLineDecorationType =
|
| 31 |
+
vscode.window.createTextEditorDecorationType({
|
| 32 |
+
backgroundColor: '#184916',
|
| 33 |
+
overviewRulerColor: 'blue',
|
| 34 |
+
overviewRulerLane: vscode.OverviewRulerLane.Right,
|
| 35 |
+
light: {
|
| 36 |
+
// this color will be used in light color themes
|
| 37 |
+
borderColor: 'darkblue',
|
| 38 |
+
},
|
| 39 |
+
dark: {
|
| 40 |
+
// this color will be used in dark color themes
|
| 41 |
+
borderColor: 'lightblue',
|
| 42 |
+
},
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
const missingLineDecorationType = vscode.window.createTextEditorDecorationType({
|
| 46 |
+
backgroundColor: '#6C2B34',
|
| 47 |
+
overviewRulerColor: 'blue',
|
| 48 |
+
overviewRulerLane: vscode.OverviewRulerLane.Right,
|
| 49 |
+
light: {
|
| 50 |
+
// this color will be used in light color themes
|
| 51 |
+
borderColor: 'darkblue',
|
| 52 |
+
},
|
| 53 |
+
dark: {
|
| 54 |
+
// this color will be used in dark color themes
|
| 55 |
+
borderColor: 'lightblue',
|
| 56 |
+
},
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
export async function loadSummaryJsonCoverage(
|
| 60 |
+
context: vscode.ExtensionContext,
|
| 61 |
+
codeCoverageFile: Uri
|
| 62 |
+
) {
|
| 63 |
+
const coverageSummaryRawJson = await vscode.workspace.openTextDocument(
|
| 64 |
+
codeCoverageFile
|
| 65 |
+
);
|
| 66 |
+
const jsonCodeCoverage = JSON.parse(coverageSummaryRawJson.getText());
|
| 67 |
+
return jsonCodeCoverage;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
export async function compareLocalToRemoteCoverage(
|
| 71 |
+
context: vscode.ExtensionContext,
|
| 72 |
+
projectName: string
|
| 73 |
+
) {
|
| 74 |
+
println('Checking the file matching');
|
| 75 |
+
/* Get the coverage from the remote server */
|
| 76 |
+
const urlString =
|
| 77 |
+
(await getOSSFuzzCloudURL(projectName)) + '/linux/summary.json';
|
| 78 |
+
|
| 79 |
+
println('URL: ' + urlString);
|
| 80 |
+
const codeCoverageFile: false | vscode.Uri = await downloadRemoteURL(
|
| 81 |
+
urlString,
|
| 82 |
+
'summary.json',
|
| 83 |
+
context
|
| 84 |
+
);
|
| 85 |
+
if (!codeCoverageFile) {
|
| 86 |
+
println('Could not get the coverage summary file');
|
| 87 |
+
return;
|
| 88 |
+
}
|
| 89 |
+
const remoteCoverage = await loadSummaryJsonCoverage(
|
| 90 |
+
context,
|
| 91 |
+
codeCoverageFile
|
| 92 |
+
);
|
| 93 |
+
|
| 94 |
+
/* Get the local coverage report */
|
| 95 |
+
// Compare the local coverage to the upstream coverage
|
| 96 |
+
const localSummaryCovPath =
|
| 97 |
+
(await getLocalOutBuildDir(projectName)) + '/report/linux/summary.json';
|
| 98 |
+
const localCodeCoverage = await loadSummaryJsonCoverage(
|
| 99 |
+
context,
|
| 100 |
+
vscode.Uri.file(localSummaryCovPath)
|
| 101 |
+
);
|
| 102 |
+
|
| 103 |
+
for (let i = 0; i < localCodeCoverage.data[0].files.length; i++) {
|
| 104 |
+
for (let j = 0; j < remoteCoverage.data[0].files.length; j++) {
|
| 105 |
+
// Get the file dictionary
|
| 106 |
+
const localFileData = localCodeCoverage.data[0].files[i];
|
| 107 |
+
const remoteFileData = remoteCoverage.data[0].files[j];
|
| 108 |
+
|
| 109 |
+
// If the filepaths are the same, then we match coverage data
|
| 110 |
+
if (localFileData.filename === remoteFileData.filename) {
|
| 111 |
+
const remoteFuncCount = remoteFileData.summary.functions.count;
|
| 112 |
+
const localFuncCount = localFileData.summary.functions.count;
|
| 113 |
+
|
| 114 |
+
if (localFuncCount > remoteFuncCount) {
|
| 115 |
+
println(
|
| 116 |
+
'Coverage improved in :' +
|
| 117 |
+
localFileData.filename +
|
| 118 |
+
' [' +
|
| 119 |
+
localFuncCount +
|
| 120 |
+
' : ' +
|
| 121 |
+
remoteFuncCount +
|
| 122 |
+
']'
|
| 123 |
+
);
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
*
|
| 132 |
+
* @param context Adds visualisation to the editor based on reading a code coverage file.
|
| 133 |
+
* @param codeCoverageFile
|
| 134 |
+
*/
|
| 135 |
+
export async function loadCoverageIntoWorkspace(
|
| 136 |
+
context: vscode.ExtensionContext,
|
| 137 |
+
codeCoverageFile: Uri
|
| 138 |
+
) {
|
| 139 |
+
isCodeCoverageEnabled = true;
|
| 140 |
+
|
| 141 |
+
const doc3 = await vscode.workspace.openTextDocument(codeCoverageFile);
|
| 142 |
+
const jsonCodeCoverageObj3 = JSON.parse(doc3.getText());
|
| 143 |
+
|
| 144 |
+
const codeCoverageMappingWithCoverage = new Map();
|
| 145 |
+
const codeCoverageMapMissingCoverage = new Map();
|
| 146 |
+
|
| 147 |
+
Object.entries(jsonCodeCoverageObj3['files']).forEach(entry => {
|
| 148 |
+
const [key, value] = entry;
|
| 149 |
+
println(key);
|
| 150 |
+
const filename = path.parse(key).base;
|
| 151 |
+
println('Filename base: ' + filename);
|
| 152 |
+
const objectDictionary: any = value as any;
|
| 153 |
+
const linesWithCodeCoverage: unknown[] = [];
|
| 154 |
+
println(objectDictionary['executed_lines']);
|
| 155 |
+
Object.entries(objectDictionary['executed_lines']).forEach(entryInner => {
|
| 156 |
+
const lineNumber = entryInner[1];
|
| 157 |
+
//println("executed line: " + lineNumber);
|
| 158 |
+
linesWithCodeCoverage.push(lineNumber);
|
| 159 |
+
});
|
| 160 |
+
codeCoverageMappingWithCoverage.set(filename, linesWithCodeCoverage);
|
| 161 |
+
|
| 162 |
+
const linesMissingCodeCoverage: unknown[] = [];
|
| 163 |
+
Object.entries(objectDictionary['missing_lines']).forEach(entryInner => {
|
| 164 |
+
const lineNumber = entryInner[1];
|
| 165 |
+
//println("executed line: " + line_numb);
|
| 166 |
+
linesMissingCodeCoverage.push(lineNumber);
|
| 167 |
+
});
|
| 168 |
+
codeCoverageMapMissingCoverage.set(filename, linesMissingCodeCoverage);
|
| 169 |
+
});
|
| 170 |
+
println('=========>');
|
| 171 |
+
|
| 172 |
+
println('Enabling code coverage decorator');
|
| 173 |
+
println('decorator sample is activated');
|
| 174 |
+
|
| 175 |
+
let timeout: NodeJS.Timer | undefined = undefined;
|
| 176 |
+
|
| 177 |
+
// create a decorator type that we use to decorate large numbers
|
| 178 |
+
|
| 179 |
+
let activeEditor = vscode.window.activeTextEditor;
|
| 180 |
+
|
| 181 |
+
function updateDecorations(
|
| 182 |
+
linesWithCodeCoverage: any,
|
| 183 |
+
linesWithoNoCodeCoverage: any
|
| 184 |
+
) {
|
| 185 |
+
if (!isCodeCoverageEnabled) {
|
| 186 |
+
return;
|
| 187 |
+
}
|
| 188 |
+
if (!activeEditor) {
|
| 189 |
+
return;
|
| 190 |
+
}
|
| 191 |
+
println('Filename');
|
| 192 |
+
println(activeEditor.document.fileName);
|
| 193 |
+
|
| 194 |
+
// Current file opened in the editor.
|
| 195 |
+
const nameOfCurrentFile = path.parse(activeEditor.document.fileName).base;
|
| 196 |
+
|
| 197 |
+
println('Base filename: ' + nameOfCurrentFile);
|
| 198 |
+
println('Done filename');
|
| 199 |
+
const lineNumbersWithCoverage: vscode.DecorationOptions[] = [];
|
| 200 |
+
const missingLineNumbers: vscode.DecorationOptions[] = [];
|
| 201 |
+
|
| 202 |
+
if (linesWithCodeCoverage.has(nameOfCurrentFile)) {
|
| 203 |
+
println('Has this file');
|
| 204 |
+
const elemWithCov = linesWithCodeCoverage.get(nameOfCurrentFile);
|
| 205 |
+
for (let idx = 0; idx < elemWithCov.length; idx++) {
|
| 206 |
+
const lineNo = elemWithCov[idx];
|
| 207 |
+
println('Setting up: ' + lineNo);
|
| 208 |
+
lineNumbersWithCoverage.push({
|
| 209 |
+
range: new vscode.Range(lineNo - 1, 0, lineNo, 0),
|
| 210 |
+
});
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
const elemNoCov = linesWithoNoCodeCoverage.get(nameOfCurrentFile);
|
| 214 |
+
for (let idx = 0; idx < elemNoCov.length; idx++) {
|
| 215 |
+
const lineNo = elemNoCov[idx];
|
| 216 |
+
println('Setting up: ' + lineNo);
|
| 217 |
+
missingLineNumbers.push({
|
| 218 |
+
range: new vscode.Range(lineNo - 1, 0, lineNo, 0),
|
| 219 |
+
});
|
| 220 |
+
}
|
| 221 |
+
} else {
|
| 222 |
+
println('Does not have this file');
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
activeEditor.setDecorations(
|
| 226 |
+
codeCoveredLineDecorationType,
|
| 227 |
+
lineNumbersWithCoverage
|
| 228 |
+
);
|
| 229 |
+
activeEditor.setDecorations(missingLineDecorationType, missingLineNumbers);
|
| 230 |
+
//activeEditor.setDecorations(largeNumberDecorationType, largeNumbers);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
function triggerUpdateDecorations(
|
| 234 |
+
throttle = false,
|
| 235 |
+
covMap: any,
|
| 236 |
+
covMisMap: any
|
| 237 |
+
) {
|
| 238 |
+
if (timeout) {
|
| 239 |
+
clearTimeout(timeout);
|
| 240 |
+
timeout = undefined;
|
| 241 |
+
}
|
| 242 |
+
if (throttle) {
|
| 243 |
+
//timeout = setTimeout(updateDecorations, 500);
|
| 244 |
+
updateDecorations(covMap, covMisMap);
|
| 245 |
+
} else {
|
| 246 |
+
updateDecorations(covMap, covMisMap);
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
if (activeEditor) {
|
| 251 |
+
triggerUpdateDecorations(
|
| 252 |
+
false,
|
| 253 |
+
codeCoverageMappingWithCoverage,
|
| 254 |
+
codeCoverageMapMissingCoverage
|
| 255 |
+
);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
vscode.window.onDidChangeActiveTextEditor(
|
| 259 |
+
editor => {
|
| 260 |
+
activeEditor = editor;
|
| 261 |
+
if (editor) {
|
| 262 |
+
triggerUpdateDecorations(
|
| 263 |
+
false,
|
| 264 |
+
codeCoverageMappingWithCoverage,
|
| 265 |
+
codeCoverageMapMissingCoverage
|
| 266 |
+
);
|
| 267 |
+
}
|
| 268 |
+
},
|
| 269 |
+
null,
|
| 270 |
+
context.subscriptions
|
| 271 |
+
);
|
| 272 |
+
|
| 273 |
+
vscode.workspace.onDidChangeTextDocument(
|
| 274 |
+
event => {
|
| 275 |
+
if (activeEditor && event.document === activeEditor.document) {
|
| 276 |
+
triggerUpdateDecorations(
|
| 277 |
+
true,
|
| 278 |
+
codeCoverageMappingWithCoverage,
|
| 279 |
+
codeCoverageMapMissingCoverage
|
| 280 |
+
);
|
| 281 |
+
}
|
| 282 |
+
},
|
| 283 |
+
null,
|
| 284 |
+
context.subscriptions
|
| 285 |
+
);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/**
|
| 289 |
+
* Removes the values from the mappings used to track code coverage. As a
|
| 290 |
+
* result, the visualisation disappears.
|
| 291 |
+
*/
|
| 292 |
+
export async function clearCoverage() {
|
| 293 |
+
// Set global indicator.
|
| 294 |
+
const activeEditor = vscode.window.activeTextEditor;
|
| 295 |
+
isCodeCoverageEnabled = false;
|
| 296 |
+
if (activeEditor) {
|
| 297 |
+
activeEditor.setDecorations(codeCoveredLineDecorationType, []);
|
| 298 |
+
activeEditor.setDecorations(missingLineDecorationType, []);
|
| 299 |
+
}
|
| 300 |
+
}
|
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/fuzzIntrospectorHelper.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2025 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 |
+
import {isPathValidOssFuzzPath} from './ossfuzzWrappers';
|
| 22 |
+
import {systemSync} from './utils';
|
| 23 |
+
|
| 24 |
+
const fs = require('fs');
|
| 25 |
+
|
| 26 |
+
export async function setUpFuzzIntrospector() {
|
| 27 |
+
println('Setting up oss-fuzz in /tmp/');
|
| 28 |
+
|
| 29 |
+
// First check if we already have Fuzz Introspector installed.
|
| 30 |
+
const tmpOssFuzzRepositoryPath = '/tmp/fi-tmp-env';
|
| 31 |
+
|
| 32 |
+
if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
|
| 33 |
+
println('Fuzz Introspector virtual env already exists in /tmp/fi-tmp-env');
|
| 34 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const cmdToExec = 'python3.11';
|
| 39 |
+
const args: Array<string> = ['-m', 'virtualenv', tmpOssFuzzRepositoryPath];
|
| 40 |
+
const [res, output] = await systemSync(cmdToExec, args);
|
| 41 |
+
if (res === false) {
|
| 42 |
+
println('Failed to create virtual environment');
|
| 43 |
+
println(output);
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
const cmdToExec2 = '/tmp/fi-tmp-env/bin/python3.11';
|
| 48 |
+
const args2: Array<string> = [
|
| 49 |
+
'-m',
|
| 50 |
+
'pip',
|
| 51 |
+
'install',
|
| 52 |
+
'fuzz-introspector==0.1.6',
|
| 53 |
+
];
|
| 54 |
+
const [res2, output2] = await systemSync(cmdToExec2, args2);
|
| 55 |
+
if (res2 === false) {
|
| 56 |
+
println('Failed to create virtual environment');
|
| 57 |
+
println(output2);
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export async function runFuzzIntrospector() {
|
| 63 |
+
println('Setting up oss-fuzz in /tmp/');
|
| 64 |
+
|
| 65 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 66 |
+
if (!workspaceFolder) {
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
const pathOfLocal = workspaceFolder[0].uri.fsPath;
|
| 70 |
+
println('path of local: ' + pathOfLocal);
|
| 71 |
+
|
| 72 |
+
// First check if we already have Fuzz Introspector installed.
|
| 73 |
+
const tmpOssFuzzRepositoryPath = '/tmp/fi-tmp-env';
|
| 74 |
+
|
| 75 |
+
if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
|
| 76 |
+
println('Fuzz Introspector virtual env already exists in /tmp/fi-tmp-env');
|
| 77 |
+
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
|
| 78 |
+
return;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
await systemSync('mkdir', ['-p', '/tmp/out-fi/']);
|
| 82 |
+
|
| 83 |
+
const cmdToExec = '/tmp/fi-tmp-env/bin/fuzz-introspector';
|
| 84 |
+
const args: Array<string> = [
|
| 85 |
+
'full',
|
| 86 |
+
'--target_dir=' + pathOfLocal,
|
| 87 |
+
'--out-dir=/tmp/out-fi',
|
| 88 |
+
];
|
| 89 |
+
const [res, output] = await systemSync(cmdToExec, args);
|
| 90 |
+
if (res === false) {
|
| 91 |
+
println('Failed run FI');
|
| 92 |
+
println(output);
|
| 93 |
+
return;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
export async function getOptimalTargetsFromIntrospector() {
|
| 98 |
+
if (!fs.existsSync('/tmp/out-fi/summary.json')) {
|
| 99 |
+
println('There are no introspector reports. Please run introspector first');
|
| 100 |
+
}
|
| 101 |
+
const json_data = fs.readFileSync('/tmp/out-fi/summary.json');
|
| 102 |
+
// println(json_data);
|
| 103 |
+
|
| 104 |
+
const jsonCodeCoverage = JSON.parse(json_data);
|
| 105 |
+
|
| 106 |
+
println('Optimal targets');
|
| 107 |
+
Object.entries(jsonCodeCoverage['analyses']['OptimalTargets']).forEach(
|
| 108 |
+
entry => {
|
| 109 |
+
const [key, value] = entry;
|
| 110 |
+
const objectDictionary: any = value as any;
|
| 111 |
+
println(JSON.stringify(objectDictionary, null, 2));
|
| 112 |
+
}
|
| 113 |
+
);
|
| 114 |
+
println('--------------------------');
|
| 115 |
+
|
| 116 |
+
return;
|
| 117 |
+
}
|
local-test-commons-compress-full-01-vuln_1/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-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/ossfu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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
const fs = require('fs');
|
| 18 |
+
import * as vscode from 'vscode';
|
| 19 |
+
import {
|
| 20 |
+
hasOssFuzzInWorkspace,
|
| 21 |
+
getOssFuzzWorkspaceProjectName,
|
| 22 |
+
listFuzzersForProject,
|
| 23 |
+
systemSyncLogIfFailure,
|
| 24 |
+
} from './utils';
|
| 25 |
+
import {println} from './logger';
|
| 26 |
+
import {extensionConfig} from './config';
|
| 27 |
+
|
| 28 |
+
export async function buildFuzzersFromWorkspaceClusterfuzzLite() {
|
| 29 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 30 |
+
if (!workspaceFolder) {
|
| 31 |
+
println('No workspace folder, exiting');
|
| 32 |
+
return false;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 36 |
+
const cmdToExec = 'python3';
|
| 37 |
+
const args = [
|
| 38 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 39 |
+
'build_fuzzers',
|
| 40 |
+
];
|
| 41 |
+
|
| 42 |
+
args.push('--external');
|
| 43 |
+
args.push(workspaceFolder[0].uri.path);
|
| 44 |
+
println('Building fuzzers');
|
| 45 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 46 |
+
println('Failed to build fuzzers');
|
| 47 |
+
return false;
|
| 48 |
+
}
|
| 49 |
+
return true;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Builds the fuzzers for a given workspace.
|
| 54 |
+
*
|
| 55 |
+
* There are two options:
|
| 56 |
+
* 1) The fuzzers are build using the OSS-Fuzz set up in the folder
|
| 57 |
+
* 2) The fuzzers are build using the workspace and then copies that over.
|
| 58 |
+
*/
|
| 59 |
+
export async function buildFuzzersFromWorkspace(
|
| 60 |
+
projectNameArg: string,
|
| 61 |
+
sanitizer: string,
|
| 62 |
+
toClean: boolean
|
| 63 |
+
) {
|
| 64 |
+
// println('Building fuzzers locally');
|
| 65 |
+
|
| 66 |
+
// Check if there is an OSS-Fuzz set up, and exit if not.
|
| 67 |
+
if (
|
| 68 |
+
(await isPathValidOssFuzzPath(
|
| 69 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 70 |
+
)) === false
|
| 71 |
+
) {
|
| 72 |
+
println('No valid oss-fuzz path');
|
| 73 |
+
return false;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 77 |
+
if (!workspaceFolder) {
|
| 78 |
+
println('No workspace folder, exiting');
|
| 79 |
+
return false;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
let ossFuzzProjectName = '';
|
| 83 |
+
if (await hasOssFuzzInWorkspace()) {
|
| 84 |
+
/**
|
| 85 |
+
* The fuzzers are in the workspace, as opposed to e.g. the oss-fuzz dirctory.
|
| 86 |
+
*/
|
| 87 |
+
ossFuzzProjectName = await getOssFuzzWorkspaceProjectName();
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* The workspace has an OSS-Fuzz directory. We use this for the build.
|
| 91 |
+
* This is done by copying over the relevant files to the oss-fuzz repository
|
| 92 |
+
* folder. Notice that we will do a forceful copy overwriting the existing
|
| 93 |
+
* project foler if it exists.
|
| 94 |
+
*/
|
| 95 |
+
println('Found project folder: ' + ossFuzzProjectName);
|
| 96 |
+
|
| 97 |
+
// Copy over the workspace oss-fuzz set up to the oss-fuzz folder.
|
| 98 |
+
let cmdToExec = 'cp';
|
| 99 |
+
let args: Array<string> = [
|
| 100 |
+
'-rfT',
|
| 101 |
+
workspaceFolder[0].uri.path + '/OSS-Fuzz/' + ossFuzzProjectName,
|
| 102 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 103 |
+
'/projects/' +
|
| 104 |
+
ossFuzzProjectName +
|
| 105 |
+
'/',
|
| 106 |
+
];
|
| 107 |
+
|
| 108 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 109 |
+
println('Failed to copy project');
|
| 110 |
+
return false;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 114 |
+
cmdToExec = 'python3';
|
| 115 |
+
args = [
|
| 116 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 117 |
+
'build_fuzzers',
|
| 118 |
+
];
|
| 119 |
+
println('DECIDING ABOUT SANITIZER');
|
| 120 |
+
if (sanitizer !== '') {
|
| 121 |
+
println('ADDING CODE COVERAGE SANITIZER');
|
| 122 |
+
args.push('--sanitizer=' + sanitizer);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
if (toClean) {
|
| 126 |
+
args.push('--clean');
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
args.push(ossFuzzProjectName);
|
| 130 |
+
println('Building fuzzers');
|
| 131 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 132 |
+
println('Failed to build fuzzers');
|
| 133 |
+
return false;
|
| 134 |
+
}
|
| 135 |
+
} else {
|
| 136 |
+
ossFuzzProjectName = projectNameArg;
|
| 137 |
+
|
| 138 |
+
const targetOssFuzzProject = vscode.Uri.file(
|
| 139 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 140 |
+
'/projects/' +
|
| 141 |
+
ossFuzzProjectName
|
| 142 |
+
);
|
| 143 |
+
// Check if the folder exists.
|
| 144 |
+
let projectHasOssFuzzFolder = false;
|
| 145 |
+
try {
|
| 146 |
+
await vscode.workspace.fs.readDirectory(targetOssFuzzProject);
|
| 147 |
+
projectHasOssFuzzFolder = true;
|
| 148 |
+
} catch {
|
| 149 |
+
projectHasOssFuzzFolder = false;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* The workspace does not have a OSS-Fuzz specific folder but has
|
| 154 |
+
* a folder in the OSS-Fuzz/projects/* directory. As such, we build
|
| 155 |
+
* the project using that build.sh set up, but, instead of cloning
|
| 156 |
+
* the repository we mount the workspace root onto what would normally
|
| 157 |
+
* be cloned.
|
| 158 |
+
*/
|
| 159 |
+
if (projectHasOssFuzzFolder) {
|
| 160 |
+
// println('Found a target directory');
|
| 161 |
+
|
| 162 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 163 |
+
// First, Set up a temporary workpath that will be cleanup after
|
| 164 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 165 |
+
const cmdToExec2 = 'cp';
|
| 166 |
+
const temporaryProjectPath =
|
| 167 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 168 |
+
'/projects/' +
|
| 169 |
+
ossFuzzProjectName +
|
| 170 |
+
'/temporary-project';
|
| 171 |
+
|
| 172 |
+
const args2: Array<string> = [
|
| 173 |
+
'-rfT',
|
| 174 |
+
wsPath.toString(),
|
| 175 |
+
temporaryProjectPath,
|
| 176 |
+
];
|
| 177 |
+
|
| 178 |
+
if (!(await systemSyncLogIfFailure(cmdToExec2, args2))) {
|
| 179 |
+
println('Failed to build fuzzers');
|
| 180 |
+
return false;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
//const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 184 |
+
const temporaryDockerPath =
|
| 185 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 186 |
+
'/projects/' +
|
| 187 |
+
ossFuzzProjectName +
|
| 188 |
+
'/Dockerfile';
|
| 189 |
+
const temporaryDockerPath2 =
|
| 190 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 191 |
+
'/projects/' +
|
| 192 |
+
ossFuzzProjectName +
|
| 193 |
+
'/Dockerfile2';
|
| 194 |
+
|
| 195 |
+
const args3: Array<string> = [temporaryDockerPath, temporaryDockerPath2];
|
| 196 |
+
if (!(await systemSyncLogIfFailure('cp', args3))) {
|
| 197 |
+
println('Failed to copy Dockerfile');
|
| 198 |
+
return false;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
// Append COPY command to Dockerfile
|
| 202 |
+
fs.appendFileSync(
|
| 203 |
+
temporaryDockerPath,
|
| 204 |
+
'COPY temporary-project /src/' + ossFuzzProjectName
|
| 205 |
+
);
|
| 206 |
+
|
| 207 |
+
// Second, build the actual fuzzers using the temporarily created project path for mount.
|
| 208 |
+
const cmdToExec = 'python3';
|
| 209 |
+
const args = [
|
| 210 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 211 |
+
'build_fuzzers', // command
|
| 212 |
+
];
|
| 213 |
+
|
| 214 |
+
// Add sanitizer if needed.
|
| 215 |
+
if (sanitizer !== '') {
|
| 216 |
+
args.push('--sanitizer=' + sanitizer);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
// Add clean flag if needed.
|
| 220 |
+
if (toClean) {
|
| 221 |
+
args.push('--clean');
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
args.push(ossFuzzProjectName);
|
| 225 |
+
/*
|
| 226 |
+
Previously we used OSS-Fuzz logic that supports mounting paths for getting
|
| 227 |
+
the workspace into the Dockerfile.
|
| 228 |
+
This approach, however, has limitations in that most builds will modify
|
| 229 |
+
the contents of the folder they're working in. This can cause issues and also
|
| 230 |
+
make it not possible to build several versions of the project with changing
|
| 231 |
+
sanitizers in a sequence. As such, we disbanded.
|
| 232 |
+
*/
|
| 233 |
+
println('Building fuzzers');
|
| 234 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 235 |
+
println('Failed to copy Dockerfile');
|
| 236 |
+
// Move back the modified Dockerfile
|
| 237 |
+
const args5: Array<string> = [
|
| 238 |
+
temporaryDockerPath2,
|
| 239 |
+
temporaryDockerPath,
|
| 240 |
+
];
|
| 241 |
+
if (!(await systemSyncLogIfFailure('mv', args5))) {
|
| 242 |
+
println('Failed to copy back Dockerfile');
|
| 243 |
+
return false;
|
| 244 |
+
}
|
| 245 |
+
return false;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
// Move back the modified Dockerfile
|
| 249 |
+
const args5: Array<string> = [temporaryDockerPath2, temporaryDockerPath];
|
| 250 |
+
if (!(await systemSyncLogIfFailure('mv', args5))) {
|
| 251 |
+
println('Failed to copy back Dockerfile');
|
| 252 |
+
return false;
|
| 253 |
+
}
|
| 254 |
+
} else {
|
| 255 |
+
println('OSS-Fuzz does not have the relevant project folder');
|
| 256 |
+
return false;
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
// If we go to here we successfully build the project. Give information.
|
| 261 |
+
vscode.window.showInformationMessage('Successfully build project');
|
| 262 |
+
|
| 263 |
+
// List the fuzzers build
|
| 264 |
+
await listFuzzersForProject(
|
| 265 |
+
ossFuzzProjectName,
|
| 266 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 267 |
+
);
|
| 268 |
+
return true;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
/**
|
| 272 |
+
* Runs the fuzzer for a given CFLite project
|
| 273 |
+
*/
|
| 274 |
+
export async function runFuzzerHandlerCFLite(
|
| 275 |
+
projectNameArg: string,
|
| 276 |
+
fuzzerNameArg: string,
|
| 277 |
+
secondsToRunArg: string
|
| 278 |
+
) {
|
| 279 |
+
// The fuzzer is run by way of OSS-Fuzz's helper.py so we use python3 to launch
|
| 280 |
+
// this script.
|
| 281 |
+
const cmdToExec = 'python3';
|
| 282 |
+
|
| 283 |
+
// Set the arguments correctly. The ordering here is important for compatibility
|
| 284 |
+
// with the underlying argparse used by OSS-Fuzz helper.py.
|
| 285 |
+
const args: Array<string> = [
|
| 286 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 287 |
+
'run_fuzzer',
|
| 288 |
+
];
|
| 289 |
+
|
| 290 |
+
args.push('--external');
|
| 291 |
+
args.push(projectNameArg);
|
| 292 |
+
args.push(fuzzerNameArg);
|
| 293 |
+
args.push('--');
|
| 294 |
+
args.push('-max_total_time=' + secondsToRunArg);
|
| 295 |
+
|
| 296 |
+
println(
|
| 297 |
+
'Running fuzzer' +
|
| 298 |
+
fuzzerNameArg +
|
| 299 |
+
' from project ' +
|
| 300 |
+
projectNameArg +
|
| 301 |
+
' for ' +
|
| 302 |
+
secondsToRunArg +
|
| 303 |
+
' seconds.'
|
| 304 |
+
);
|
| 305 |
+
|
| 306 |
+
// Run the actual command
|
| 307 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 308 |
+
println('Failed to run fuzzer');
|
| 309 |
+
return false;
|
| 310 |
+
}
|
| 311 |
+
return true;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
/**
|
| 315 |
+
* Runs the fuzzer for a given project.
|
| 316 |
+
*/
|
| 317 |
+
export async function runFuzzerHandler(
|
| 318 |
+
projectNameArg: string,
|
| 319 |
+
fuzzerNameArg: string,
|
| 320 |
+
secondsToRunArg: string,
|
| 321 |
+
fuzzerCorpusPath: string
|
| 322 |
+
) {
|
| 323 |
+
// Check there is a valid OSS-Fuzz path. If not, bail out.
|
| 324 |
+
if (
|
| 325 |
+
(await isPathValidOssFuzzPath(
|
| 326 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 327 |
+
)) === false
|
| 328 |
+
) {
|
| 329 |
+
println('Missing valid OSS-Fuzz path.');
|
| 330 |
+
return;
|
| 331 |
+
}
|
| 332 |
+
// The fuzzer is run by way of OSS-Fuzz's helper.py so we use python3 to launch
|
| 333 |
+
// this script.
|
| 334 |
+
const cmdToExec = 'python3';
|
| 335 |
+
|
| 336 |
+
// Set the arguments correctly. The ordering here is important for compatibility
|
| 337 |
+
// with the underlying argparse used by OSS-Fuzz helper.py.
|
| 338 |
+
const args: Array<string> = [
|
| 339 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 340 |
+
'run_fuzzer',
|
| 341 |
+
];
|
| 342 |
+
if (fuzzerCorpusPath !== '') {
|
| 343 |
+
args.push('--corpus-dir');
|
| 344 |
+
args.push(fuzzerCorpusPath);
|
| 345 |
+
}
|
| 346 |
+
args.push(projectNameArg);
|
| 347 |
+
args.push(fuzzerNameArg);
|
| 348 |
+
args.push('--');
|
| 349 |
+
args.push('-max_total_time=' + secondsToRunArg);
|
| 350 |
+
|
| 351 |
+
println(
|
| 352 |
+
'Running fuzzer' +
|
| 353 |
+
fuzzerNameArg +
|
| 354 |
+
' from project ' +
|
| 355 |
+
projectNameArg +
|
| 356 |
+
' for ' +
|
| 357 |
+
secondsToRunArg +
|
| 358 |
+
' seconds.'
|
| 359 |
+
);
|
| 360 |
+
|
| 361 |
+
// Run the actual command
|
| 362 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 363 |
+
println('Failed to run fuzzer');
|
| 364 |
+
return false;
|
| 365 |
+
}
|
| 366 |
+
return true;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
// Validates if a directory is a valid oss-fuzz path.
|
| 370 |
+
export async function isPathValidOssFuzzPath(path: string) {
|
| 371 |
+
try {
|
| 372 |
+
if (await vscode.workspace.fs.readDirectory(vscode.Uri.file(path))) {
|
| 373 |
+
// println('Is a directory');
|
| 374 |
+
// const helperPath = vscode.Uri.file(path + '/infra/helper.py');
|
| 375 |
+
const helperPath = path + '/infra/helper.py';
|
| 376 |
+
//console.log('Checking ' + helperPath.toString());
|
| 377 |
+
if (fs.existsSync(helperPath.toString())) {
|
| 378 |
+
return true;
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
} catch {
|
| 382 |
+
/* empty */
|
| 383 |
+
}
|
| 384 |
+
return false;
|
| 385 |
+
}
|
local-test-commons-compress-full-01-vuln_1/fuzz-tooling/tools/vscode-extension/src/projectIntegrationHelper.ts
ADDED
|
@@ -0,0 +1,761 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
// 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 path = require('path');
|
| 20 |
+
import {println} from './logger';
|
| 21 |
+
import * as fuzzTemplate from './commands/cmdTemplate';
|
| 22 |
+
|
| 23 |
+
export async function setupProjectInitialFiles(isClusterfuzzLite: boolean) {
|
| 24 |
+
const wsedit = new vscode.WorkspaceEdit();
|
| 25 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 26 |
+
let projectGithubRepository = '';
|
| 27 |
+
|
| 28 |
+
const isOssFuzz = isClusterfuzzLite === false;
|
| 29 |
+
|
| 30 |
+
// Get the repository if this is not ClusterfuzzLite
|
| 31 |
+
if (isOssFuzz) {
|
| 32 |
+
const tmpProjectGithubRepository = await vscode.window.showInputBox({
|
| 33 |
+
value: '',
|
| 34 |
+
placeHolder: 'Github repository for the project.',
|
| 35 |
+
});
|
| 36 |
+
if (!tmpProjectGithubRepository) {
|
| 37 |
+
return false;
|
| 38 |
+
}
|
| 39 |
+
projectGithubRepository = tmpProjectGithubRepository;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
const projectNameFromRepo = path
|
| 43 |
+
.parse(projectGithubRepository)
|
| 44 |
+
.base.toLocaleLowerCase();
|
| 45 |
+
|
| 46 |
+
let pathOfLocal = '';
|
| 47 |
+
if (workspaceFolder) {
|
| 48 |
+
pathOfLocal = path
|
| 49 |
+
.parse(workspaceFolder[0].uri.fsPath)
|
| 50 |
+
.base.toLocaleLowerCase();
|
| 51 |
+
println('path of local: ' + pathOfLocal);
|
| 52 |
+
}
|
| 53 |
+
if (isOssFuzz) {
|
| 54 |
+
println('Derived project name: ' + projectNameFromRepo);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
const pythonFiles = await vscode.workspace.findFiles('**/*.py');
|
| 58 |
+
const cppFiles = await vscode.workspace.findFiles('**/*.c++');
|
| 59 |
+
const cppFiles2 = await vscode.workspace.findFiles('**/*.cpp');
|
| 60 |
+
const cppFiles3 = await vscode.workspace.findFiles('**/*.cc');
|
| 61 |
+
const cfiles = await vscode.workspace.findFiles('**/*.c');
|
| 62 |
+
const hfiles = await vscode.workspace.findFiles('**/*.h');
|
| 63 |
+
const rustFiles = await vscode.workspace.findFiles('**/*.rust');
|
| 64 |
+
const golangFiles = await vscode.workspace.findFiles('**/*.go');
|
| 65 |
+
const javaFiles = await vscode.workspace.findFiles('**/*.java');
|
| 66 |
+
|
| 67 |
+
println('Number of python files: ' + pythonFiles.length);
|
| 68 |
+
println('Number of C++ files: ' + cppFiles.length + cppFiles2.length);
|
| 69 |
+
println('Number of C files: ' + cfiles.length);
|
| 70 |
+
println('Number of rustFiles files: ' + rustFiles.length);
|
| 71 |
+
println('Number of golangFiles files: ' + golangFiles.length);
|
| 72 |
+
println('Number of H files: ' + hfiles.length);
|
| 73 |
+
|
| 74 |
+
const cppFilesCount = cppFiles.length + cppFiles2.length + cppFiles3.length;
|
| 75 |
+
|
| 76 |
+
const maxCount = Math.max(
|
| 77 |
+
pythonFiles.length,
|
| 78 |
+
cppFilesCount,
|
| 79 |
+
cfiles.length,
|
| 80 |
+
rustFiles.length,
|
| 81 |
+
golangFiles.length,
|
| 82 |
+
javaFiles.length
|
| 83 |
+
);
|
| 84 |
+
let target = '';
|
| 85 |
+
if (maxCount > 0) {
|
| 86 |
+
if (maxCount === pythonFiles.length) {
|
| 87 |
+
target = 'python';
|
| 88 |
+
} else if (maxCount === cppFilesCount) {
|
| 89 |
+
target = 'cpp';
|
| 90 |
+
} else if (maxCount === cfiles.length) {
|
| 91 |
+
target = 'c';
|
| 92 |
+
} else if (maxCount === javaFiles.length) {
|
| 93 |
+
target = 'java';
|
| 94 |
+
} else {
|
| 95 |
+
println('Target is not implemented');
|
| 96 |
+
return true;
|
| 97 |
+
}
|
| 98 |
+
} else {
|
| 99 |
+
if (hfiles.length > 0) {
|
| 100 |
+
target = 'cpp';
|
| 101 |
+
} else {
|
| 102 |
+
return true;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
println('Target language: ' + target);
|
| 107 |
+
|
| 108 |
+
let baseFolder = '.clusterfuzzlite';
|
| 109 |
+
if (isOssFuzz) {
|
| 110 |
+
baseFolder = 'OSS-Fuzz';
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
if (workspaceFolder) {
|
| 114 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 115 |
+
|
| 116 |
+
// Create workflow file for ClusterFuzzLite
|
| 117 |
+
if (isOssFuzz === false) {
|
| 118 |
+
println('Creating the workflow file');
|
| 119 |
+
const clusterfuzzWorkflowFile = vscode.Uri.file(
|
| 120 |
+
wsPath + '/' + '.github' + '/' + 'workflows/cflite_pr.yml'
|
| 121 |
+
);
|
| 122 |
+
|
| 123 |
+
let tmp_target = target;
|
| 124 |
+
if (tmp_target === 'cpp') {
|
| 125 |
+
tmp_target = 'c++';
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
//println('Workflow pth: ' + clusterfuzzWorkflowFile);
|
| 129 |
+
|
| 130 |
+
const cflite_workflow_yaml = `name: ClusterFuzzLite PR fuzzing
|
| 131 |
+
on:
|
| 132 |
+
workflow_dispatch:
|
| 133 |
+
pull_request:
|
| 134 |
+
branches: [ main ]
|
| 135 |
+
permissions: read-all
|
| 136 |
+
jobs:
|
| 137 |
+
PR:
|
| 138 |
+
runs-on: ubuntu-latest
|
| 139 |
+
strategy:
|
| 140 |
+
fail-fast: false
|
| 141 |
+
matrix:
|
| 142 |
+
sanitizer: [address]
|
| 143 |
+
steps:
|
| 144 |
+
- name: Build Fuzzers (\${{ matrix.sanitizer }})
|
| 145 |
+
id: build
|
| 146 |
+
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
|
| 147 |
+
with:
|
| 148 |
+
sanitizer: \${{ matrix.sanitizer }}
|
| 149 |
+
language: ${tmp_target}
|
| 150 |
+
bad-build-check: false
|
| 151 |
+
- name: Run Fuzzers (\${{ matrix.sanitizer }})
|
| 152 |
+
id: run
|
| 153 |
+
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
|
| 154 |
+
with:
|
| 155 |
+
github-token: \${{ secrets.GITHUB_TOKEN }}
|
| 156 |
+
fuzz-seconds: 100
|
| 157 |
+
mode: 'code-change'
|
| 158 |
+
report-unreproducible-crashes: false
|
| 159 |
+
sanitizer: \${{ matrix.sanitizer }}
|
| 160 |
+
`;
|
| 161 |
+
|
| 162 |
+
// Create the file and add the contents
|
| 163 |
+
if (fs.existsSync(clusterfuzzWorkflowFile.path) === false) {
|
| 164 |
+
wsedit.createFile(clusterfuzzWorkflowFile, {ignoreIfExists: true});
|
| 165 |
+
wsedit.insert(
|
| 166 |
+
clusterfuzzWorkflowFile,
|
| 167 |
+
new vscode.Position(0, 0),
|
| 168 |
+
cflite_workflow_yaml
|
| 169 |
+
);
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
const ossfuzzDockerFilepath = vscode.Uri.file(
|
| 174 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/Dockerfile'
|
| 175 |
+
);
|
| 176 |
+
|
| 177 |
+
vscode.window.showInformationMessage(ossfuzzDockerFilepath.toString());
|
| 178 |
+
//wsedit.createFile(ossfuzzDockerFilepath, {ignoreIfExists: true});
|
| 179 |
+
|
| 180 |
+
if (target === 'python') {
|
| 181 |
+
await setupPythonProjectInitialFiles(
|
| 182 |
+
projectGithubRepository,
|
| 183 |
+
projectNameFromRepo,
|
| 184 |
+
ossfuzzDockerFilepath,
|
| 185 |
+
wsedit,
|
| 186 |
+
wsPath,
|
| 187 |
+
baseFolder,
|
| 188 |
+
pathOfLocal,
|
| 189 |
+
isOssFuzz
|
| 190 |
+
);
|
| 191 |
+
}
|
| 192 |
+
if (target === 'cpp') {
|
| 193 |
+
await setupCPPProjectInitialFiles(
|
| 194 |
+
projectGithubRepository,
|
| 195 |
+
projectNameFromRepo,
|
| 196 |
+
ossfuzzDockerFilepath,
|
| 197 |
+
wsedit,
|
| 198 |
+
wsPath,
|
| 199 |
+
baseFolder,
|
| 200 |
+
pathOfLocal,
|
| 201 |
+
isOssFuzz
|
| 202 |
+
);
|
| 203 |
+
}
|
| 204 |
+
if (target === 'c') {
|
| 205 |
+
await setupCProjectInitialFiles(
|
| 206 |
+
projectGithubRepository,
|
| 207 |
+
projectNameFromRepo,
|
| 208 |
+
ossfuzzDockerFilepath,
|
| 209 |
+
wsedit,
|
| 210 |
+
wsPath,
|
| 211 |
+
baseFolder,
|
| 212 |
+
pathOfLocal,
|
| 213 |
+
isOssFuzz
|
| 214 |
+
);
|
| 215 |
+
}
|
| 216 |
+
if (target === 'java') {
|
| 217 |
+
await setupJavaProjectInitialFiles(
|
| 218 |
+
projectGithubRepository,
|
| 219 |
+
projectNameFromRepo,
|
| 220 |
+
ossfuzzDockerFilepath,
|
| 221 |
+
wsedit,
|
| 222 |
+
wsPath,
|
| 223 |
+
baseFolder,
|
| 224 |
+
isOssFuzz
|
| 225 |
+
);
|
| 226 |
+
}
|
| 227 |
+
vscode.workspace.applyEdit(wsedit);
|
| 228 |
+
vscode.window.showInformationMessage('Created a new file: hello/world.md');
|
| 229 |
+
}
|
| 230 |
+
return true;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
function createProjectYamlContent(
|
| 234 |
+
wsedit: vscode.WorkspaceEdit,
|
| 235 |
+
wsPath: string,
|
| 236 |
+
baseFolder: string,
|
| 237 |
+
isOssFuzz: boolean,
|
| 238 |
+
projectGithubRepository: string,
|
| 239 |
+
projectNameFromRepo: string,
|
| 240 |
+
language: string
|
| 241 |
+
) {
|
| 242 |
+
const projectYamlFilepath = vscode.Uri.file(
|
| 243 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/project.yaml'
|
| 244 |
+
);
|
| 245 |
+
if (fs.existsSync(projectYamlFilepath.path) === false) {
|
| 246 |
+
vscode.window.showInformationMessage(projectYamlFilepath.toString());
|
| 247 |
+
wsedit.createFile(projectYamlFilepath, {ignoreIfExists: true});
|
| 248 |
+
const projectYamlTemplate = `homepage: "${projectGithubRepository}"
|
| 249 |
+
language: ${language}
|
| 250 |
+
primary_contact: "<primary_contact_email>"
|
| 251 |
+
main_repo: "${projectGithubRepository}"
|
| 252 |
+
file_github_issue: true
|
| 253 |
+
`;
|
| 254 |
+
|
| 255 |
+
const projectYamlTemplateCFLite = `language: ${language}`;
|
| 256 |
+
|
| 257 |
+
const yamlContentToWrite = isOssFuzz
|
| 258 |
+
? projectYamlTemplate
|
| 259 |
+
: projectYamlTemplateCFLite;
|
| 260 |
+
|
| 261 |
+
wsedit.insert(
|
| 262 |
+
projectYamlFilepath,
|
| 263 |
+
new vscode.Position(0, 0),
|
| 264 |
+
yamlContentToWrite
|
| 265 |
+
);
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
function getLicenseHeader() {
|
| 270 |
+
const todaysDate = new Date();
|
| 271 |
+
const currentYear = todaysDate.getFullYear();
|
| 272 |
+
|
| 273 |
+
const licenseHeader = `# Copyright ${currentYear} Google LLC
|
| 274 |
+
#
|
| 275 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 276 |
+
# you may not use this file except in compliance with the License.
|
| 277 |
+
# You may obtain a copy of the License at
|
| 278 |
+
#
|
| 279 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 280 |
+
#
|
| 281 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 282 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 283 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 284 |
+
# See the License for the specific language governing permissions and
|
| 285 |
+
# limitations under the License.
|
| 286 |
+
#
|
| 287 |
+
################################################################################
|
| 288 |
+
`;
|
| 289 |
+
|
| 290 |
+
return licenseHeader;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
function getBaseDockerFile(language: string) {
|
| 294 |
+
const languageToBasebuilder: {[id: string]: string} = {
|
| 295 |
+
java: 'ghcr.io/aixcc-finals/base-builder-jvm',
|
| 296 |
+
cpp: 'ghcr.io/aixcc-finals/base-builder',
|
| 297 |
+
c: 'ghcr.io/aixcc-finals/base-builder',
|
| 298 |
+
python: 'ghcr.io/aixcc-finals/base-builder-python',
|
| 299 |
+
};
|
| 300 |
+
let dockerFileContent = getLicenseHeader();
|
| 301 |
+
dockerFileContent += '\n' + 'FROM ' + languageToBasebuilder[language] + '\n';
|
| 302 |
+
|
| 303 |
+
return dockerFileContent;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
function createReadmeFile(
|
| 307 |
+
wsedit: vscode.WorkspaceEdit,
|
| 308 |
+
wsPath: string,
|
| 309 |
+
baseFolder: string,
|
| 310 |
+
isOssFuzz: boolean
|
| 311 |
+
) {
|
| 312 |
+
const readmeFile = vscode.Uri.file(
|
| 313 |
+
wsPath + '/' + baseFolder + '/' + '/README.md'
|
| 314 |
+
);
|
| 315 |
+
//vscode.window.showInformationMessage(readmeFile.toString());
|
| 316 |
+
if (fs.existsSync(readmeFile.path) === false) {
|
| 317 |
+
const readmeContents = `# OSS-Fuzz set up
|
| 318 |
+
This folder is the OSS-Fuzz set up.
|
| 319 |
+
`;
|
| 320 |
+
|
| 321 |
+
const readmeContentsCFLite = `# ClusterFuzzLite set up
|
| 322 |
+
This folder contains a fuzzing set for [ClusterFuzzLite](https://google.github.io/clusterfuzzlite).
|
| 323 |
+
`;
|
| 324 |
+
|
| 325 |
+
const readmeContentsToWrite = isOssFuzz
|
| 326 |
+
? readmeContents
|
| 327 |
+
: readmeContentsCFLite;
|
| 328 |
+
|
| 329 |
+
wsedit.createFile(readmeFile, {ignoreIfExists: true});
|
| 330 |
+
|
| 331 |
+
wsedit.insert(readmeFile, new vscode.Position(0, 0), readmeContentsToWrite);
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
async function setupJavaProjectInitialFiles(
|
| 336 |
+
projectGithubRepository: string,
|
| 337 |
+
projectNameFromRepo: string,
|
| 338 |
+
ossfuzzDockerFilepath: vscode.Uri,
|
| 339 |
+
wsedit: vscode.WorkspaceEdit,
|
| 340 |
+
wsPath: string,
|
| 341 |
+
baseFolder: string,
|
| 342 |
+
isOssFuzz: boolean
|
| 343 |
+
) {
|
| 344 |
+
// Dockerfile
|
| 345 |
+
const dockerfileTemplate =
|
| 346 |
+
getBaseDockerFile('java') +
|
| 347 |
+
`
|
| 348 |
+
RUN curl -L https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip -o maven.zip && \\
|
| 349 |
+
unzip maven.zip -d $SRC/maven && \\
|
| 350 |
+
rm -rf maven.zip
|
| 351 |
+
|
| 352 |
+
ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn
|
| 353 |
+
RUN git clone --depth 1 ${projectGithubRepository} ${projectNameFromRepo}
|
| 354 |
+
WORKDIR ${projectNameFromRepo}
|
| 355 |
+
COPY build.sh *.java $SRC/`;
|
| 356 |
+
wsedit.insert(
|
| 357 |
+
ossfuzzDockerFilepath,
|
| 358 |
+
new vscode.Position(0, 0),
|
| 359 |
+
dockerfileTemplate
|
| 360 |
+
);
|
| 361 |
+
|
| 362 |
+
// build.sh
|
| 363 |
+
const ossfuzzBuildFilepath = vscode.Uri.file(
|
| 364 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/build.sh'
|
| 365 |
+
);
|
| 366 |
+
vscode.window.showInformationMessage(ossfuzzBuildFilepath.toString());
|
| 367 |
+
wsedit.createFile(ossfuzzBuildFilepath, {ignoreIfExists: true});
|
| 368 |
+
const buildTemplate =
|
| 369 |
+
`#!/bin/bash -eu
|
| 370 |
+
` +
|
| 371 |
+
getLicenseHeader() +
|
| 372 |
+
`
|
| 373 |
+
# Supply build instructions
|
| 374 |
+
# Copy all fuzzer executables to $OUT/
|
| 375 |
+
`;
|
| 376 |
+
wsedit.insert(ossfuzzBuildFilepath, new vscode.Position(0, 0), buildTemplate);
|
| 377 |
+
|
| 378 |
+
// project.yaml
|
| 379 |
+
createProjectYamlContent(
|
| 380 |
+
wsedit,
|
| 381 |
+
wsPath,
|
| 382 |
+
baseFolder,
|
| 383 |
+
isOssFuzz,
|
| 384 |
+
projectGithubRepository,
|
| 385 |
+
projectNameFromRepo,
|
| 386 |
+
'jvm'
|
| 387 |
+
);
|
| 388 |
+
|
| 389 |
+
/* Sample template fuzzer */
|
| 390 |
+
const sampleFuzzFile = vscode.Uri.file(
|
| 391 |
+
wsPath +
|
| 392 |
+
'/' +
|
| 393 |
+
baseFolder +
|
| 394 |
+
'/' +
|
| 395 |
+
projectNameFromRepo +
|
| 396 |
+
'/fuzzer_example.java'
|
| 397 |
+
);
|
| 398 |
+
|
| 399 |
+
wsedit.createFile(sampleFuzzFile, {ignoreIfExists: true});
|
| 400 |
+
const sampleFuzzFileContents = fuzzTemplate.javaLangBareTemplate;
|
| 401 |
+
|
| 402 |
+
wsedit.insert(
|
| 403 |
+
sampleFuzzFile,
|
| 404 |
+
new vscode.Position(0, 0),
|
| 405 |
+
sampleFuzzFileContents
|
| 406 |
+
);
|
| 407 |
+
|
| 408 |
+
createReadmeFile(wsedit, wsPath, baseFolder, isOssFuzz);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
async function setupCProjectInitialFiles(
|
| 412 |
+
projectGithubRepository: string,
|
| 413 |
+
projectNameFromRepo: string,
|
| 414 |
+
ossfuzzDockerFilepath: vscode.Uri,
|
| 415 |
+
wsedit: vscode.WorkspaceEdit,
|
| 416 |
+
wsPath: string,
|
| 417 |
+
baseFolder: string,
|
| 418 |
+
baseName: string,
|
| 419 |
+
isOssFuzz: boolean
|
| 420 |
+
) {
|
| 421 |
+
// Dockerfile
|
| 422 |
+
if (fs.existsSync(ossfuzzDockerFilepath.path) === false) {
|
| 423 |
+
const dockerfileTemplate =
|
| 424 |
+
getBaseDockerFile('cpp') +
|
| 425 |
+
`
|
| 426 |
+
RUN apt-get update && apt-get install -y make autoconf automake libtool
|
| 427 |
+
RUN git clone --depth 1 ${projectGithubRepository} ${projectNameFromRepo}
|
| 428 |
+
WORKDIR ${projectNameFromRepo}
|
| 429 |
+
COPY build.sh *.cpp $SRC/`;
|
| 430 |
+
|
| 431 |
+
const dockerfileTemplateClusterfuzzLite = `FROM ghcr.io/aixcc-finals/base-builder
|
| 432 |
+
RUN apt-get update && apt-get install -y make autoconf automake libtool
|
| 433 |
+
|
| 434 |
+
COPY . $SRC/${baseName}
|
| 435 |
+
COPY .clusterfuzzlite/build.sh $SRC/build.sh
|
| 436 |
+
WORKDIR $SRC/${baseName}`;
|
| 437 |
+
|
| 438 |
+
const contentToWrite = isOssFuzz
|
| 439 |
+
? dockerfileTemplate
|
| 440 |
+
: dockerfileTemplateClusterfuzzLite;
|
| 441 |
+
|
| 442 |
+
// Create the file and add the contents
|
| 443 |
+
wsedit.createFile(ossfuzzDockerFilepath, {ignoreIfExists: true});
|
| 444 |
+
wsedit.insert(
|
| 445 |
+
ossfuzzDockerFilepath,
|
| 446 |
+
new vscode.Position(0, 0),
|
| 447 |
+
contentToWrite
|
| 448 |
+
);
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
// build.sh
|
| 452 |
+
const ossfuzzBuildFilepath = vscode.Uri.file(
|
| 453 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/build.sh'
|
| 454 |
+
);
|
| 455 |
+
// Only create the build file if it doesn't exist
|
| 456 |
+
if (fs.existsSync(ossfuzzBuildFilepath.path) === false) {
|
| 457 |
+
vscode.window.showInformationMessage(ossfuzzBuildFilepath.toString());
|
| 458 |
+
wsedit.createFile(ossfuzzBuildFilepath, {ignoreIfExists: true});
|
| 459 |
+
const buildTemplate =
|
| 460 |
+
`#!/bin/bash -eu
|
| 461 |
+
` +
|
| 462 |
+
getLicenseHeader() +
|
| 463 |
+
`
|
| 464 |
+
# Supply build instructions
|
| 465 |
+
# Use the following environment variables to build the code
|
| 466 |
+
# $CXX: c++ compiler
|
| 467 |
+
# $CC: c compiler
|
| 468 |
+
# CFLAGS: compiler flags for C files
|
| 469 |
+
# CXXFLAGS: compiler flags for CPP files
|
| 470 |
+
# LIB_FUZZING_ENGINE: linker flag for fuzzing harnesses
|
| 471 |
+
|
| 472 |
+
# Copy all fuzzer executables to $OUT/
|
| 473 |
+
$CXX $CFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer_example.c -o $OUT/fuzzer_example
|
| 474 |
+
`;
|
| 475 |
+
|
| 476 |
+
const buildTemplateClusterfuzzLite = `#!/bin/bash -eu
|
| 477 |
+
# Supply build instructions
|
| 478 |
+
# Use the following environment variables to build the code
|
| 479 |
+
# $CXX: c++ compiler
|
| 480 |
+
# $CC: c compiler
|
| 481 |
+
# CFLAGS: compiler flags for C files
|
| 482 |
+
# CXXFLAGS: compiler flags for CPP files
|
| 483 |
+
# LIB_FUZZING_ENGINE: linker flag for fuzzing harnesses
|
| 484 |
+
|
| 485 |
+
# Copy all fuzzer executables to $OUT/
|
| 486 |
+
$CC $CFLAGS $LIB_FUZZING_ENGINE \\
|
| 487 |
+
$SRC/${baseName}/.clusterfuzzlite/fuzzer_example.c \\
|
| 488 |
+
-o $OUT/fuzzer_example
|
| 489 |
+
`;
|
| 490 |
+
|
| 491 |
+
const buildContent = isOssFuzz
|
| 492 |
+
? buildTemplate
|
| 493 |
+
: buildTemplateClusterfuzzLite;
|
| 494 |
+
wsedit.insert(
|
| 495 |
+
ossfuzzBuildFilepath,
|
| 496 |
+
new vscode.Position(0, 0),
|
| 497 |
+
buildContent
|
| 498 |
+
);
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
// project.yaml
|
| 502 |
+
createProjectYamlContent(
|
| 503 |
+
wsedit,
|
| 504 |
+
wsPath,
|
| 505 |
+
baseFolder,
|
| 506 |
+
isOssFuzz,
|
| 507 |
+
projectGithubRepository,
|
| 508 |
+
projectNameFromRepo,
|
| 509 |
+
'c'
|
| 510 |
+
);
|
| 511 |
+
|
| 512 |
+
/* Sample template fuzzer */
|
| 513 |
+
const sampleFuzzFile = vscode.Uri.file(
|
| 514 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/fuzzer_example.c'
|
| 515 |
+
);
|
| 516 |
+
if (fs.existsSync(sampleFuzzFile.path) === false) {
|
| 517 |
+
wsedit.createFile(sampleFuzzFile, {ignoreIfExists: true});
|
| 518 |
+
const sampleFuzzFileContents = fuzzTemplate.cLangSimpleStringFuzzer;
|
| 519 |
+
|
| 520 |
+
wsedit.insert(
|
| 521 |
+
sampleFuzzFile,
|
| 522 |
+
new vscode.Position(0, 0),
|
| 523 |
+
sampleFuzzFileContents
|
| 524 |
+
);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
createReadmeFile(wsedit, wsPath, baseFolder, isOssFuzz);
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
async function setupCPPProjectInitialFiles(
|
| 531 |
+
projectGithubRepository: string,
|
| 532 |
+
projectNameFromRepo: string,
|
| 533 |
+
ossfuzzDockerFilepath: vscode.Uri,
|
| 534 |
+
wsedit: vscode.WorkspaceEdit,
|
| 535 |
+
wsPath: string,
|
| 536 |
+
baseFolder: string,
|
| 537 |
+
baseName: string,
|
| 538 |
+
isOssFuzz: boolean
|
| 539 |
+
) {
|
| 540 |
+
// Dockerfile
|
| 541 |
+
// Only create a new Dockerfile if it doesn't already exist
|
| 542 |
+
if (fs.existsSync(ossfuzzDockerFilepath.path) === false) {
|
| 543 |
+
const dockerfileTemplate =
|
| 544 |
+
getBaseDockerFile('cpp') +
|
| 545 |
+
`
|
| 546 |
+
RUN apt-get update && apt-get install -y make autoconf automake libtool
|
| 547 |
+
RUN git clone --depth 1 ${projectGithubRepository} ${projectNameFromRepo}
|
| 548 |
+
WORKDIR ${projectNameFromRepo}
|
| 549 |
+
COPY build.sh *.cpp $SRC/`;
|
| 550 |
+
|
| 551 |
+
const dockerfileTemplateClusterfuzzLite = `FROM ghcr.io/aixcc-finals/base-builder
|
| 552 |
+
RUN apt-get update && apt-get install -y make autoconf automake libtool
|
| 553 |
+
|
| 554 |
+
COPY . $SRC/${baseName}
|
| 555 |
+
COPY .clusterfuzzlite/build.sh $SRC/build.sh
|
| 556 |
+
WORKDIR $SRC/${baseName}`;
|
| 557 |
+
|
| 558 |
+
const contentToWrite = isOssFuzz
|
| 559 |
+
? dockerfileTemplate
|
| 560 |
+
: dockerfileTemplateClusterfuzzLite;
|
| 561 |
+
|
| 562 |
+
// Create the file and add the contents
|
| 563 |
+
wsedit.createFile(ossfuzzDockerFilepath, {ignoreIfExists: true});
|
| 564 |
+
wsedit.insert(
|
| 565 |
+
ossfuzzDockerFilepath,
|
| 566 |
+
new vscode.Position(0, 0),
|
| 567 |
+
contentToWrite
|
| 568 |
+
);
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
// build.sh
|
| 572 |
+
const ossfuzzBuildFilepath = vscode.Uri.file(
|
| 573 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/build.sh'
|
| 574 |
+
);
|
| 575 |
+
// Only create the build file if it doesn't exist
|
| 576 |
+
if (fs.existsSync(ossfuzzBuildFilepath.path) === false) {
|
| 577 |
+
vscode.window.showInformationMessage(ossfuzzBuildFilepath.toString());
|
| 578 |
+
wsedit.createFile(ossfuzzBuildFilepath, {ignoreIfExists: true});
|
| 579 |
+
const buildTemplate =
|
| 580 |
+
`#!/bin/bash -eu
|
| 581 |
+
` +
|
| 582 |
+
getLicenseHeader() +
|
| 583 |
+
`
|
| 584 |
+
# Supply build instructions
|
| 585 |
+
# Use the following environment variables to build the code
|
| 586 |
+
# $CXX: c++ compiler
|
| 587 |
+
# $CC: c compiler
|
| 588 |
+
# CFLAGS: compiler flags for C files
|
| 589 |
+
# CXXFLAGS: compiler flags for CPP files
|
| 590 |
+
# LIB_FUZZING_ENGINE: linker flag for fuzzing harnesses
|
| 591 |
+
|
| 592 |
+
# Copy all fuzzer executables to $OUT/
|
| 593 |
+
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $SRC/fuzzer_example.cpp -o $OUT/fuzzer_example
|
| 594 |
+
`;
|
| 595 |
+
const buildTemplateClusterfuzzLite = `#!/bin/bash -eu
|
| 596 |
+
# Supply build instructions
|
| 597 |
+
# Use the following environment variables to build the code
|
| 598 |
+
# $CXX: c++ compiler
|
| 599 |
+
# $CC: c compiler
|
| 600 |
+
# CFLAGS: compiler flags for C files
|
| 601 |
+
# CXXFLAGS: compiler flags for CPP files
|
| 602 |
+
# LIB_FUZZING_ENGINE: linker flag for fuzzing harnesses
|
| 603 |
+
|
| 604 |
+
# Copy all fuzzer executables to $OUT/
|
| 605 |
+
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE \\
|
| 606 |
+
$SRC/${baseName}/.clusterfuzzlite/fuzzer_example.cpp \\
|
| 607 |
+
-o $OUT/fuzzer_example
|
| 608 |
+
`;
|
| 609 |
+
|
| 610 |
+
const buildContent = isOssFuzz
|
| 611 |
+
? buildTemplate
|
| 612 |
+
: buildTemplateClusterfuzzLite;
|
| 613 |
+
wsedit.insert(
|
| 614 |
+
ossfuzzBuildFilepath,
|
| 615 |
+
new vscode.Position(0, 0),
|
| 616 |
+
buildContent
|
| 617 |
+
);
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
// project.yaml
|
| 621 |
+
createProjectYamlContent(
|
| 622 |
+
wsedit,
|
| 623 |
+
wsPath,
|
| 624 |
+
baseFolder,
|
| 625 |
+
isOssFuzz,
|
| 626 |
+
projectGithubRepository,
|
| 627 |
+
projectNameFromRepo,
|
| 628 |
+
'c++'
|
| 629 |
+
);
|
| 630 |
+
|
| 631 |
+
/* Sample template fuzzer */
|
| 632 |
+
const sampleFuzzFile = vscode.Uri.file(
|
| 633 |
+
wsPath +
|
| 634 |
+
'/' +
|
| 635 |
+
baseFolder +
|
| 636 |
+
'/' +
|
| 637 |
+
projectNameFromRepo +
|
| 638 |
+
'/fuzzer_example.cpp'
|
| 639 |
+
);
|
| 640 |
+
if (fs.existsSync(sampleFuzzFile.path) === false) {
|
| 641 |
+
wsedit.createFile(sampleFuzzFile, {ignoreIfExists: true});
|
| 642 |
+
const sampleFuzzFileContents = fuzzTemplate.cppLangFDPTemplateFuzzer;
|
| 643 |
+
|
| 644 |
+
wsedit.insert(
|
| 645 |
+
sampleFuzzFile,
|
| 646 |
+
new vscode.Position(0, 0),
|
| 647 |
+
sampleFuzzFileContents
|
| 648 |
+
);
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
createReadmeFile(wsedit, wsPath, baseFolder, isOssFuzz);
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
async function setupPythonProjectInitialFiles(
|
| 655 |
+
projectGithubRepository: string,
|
| 656 |
+
projectNameFromRepo: string,
|
| 657 |
+
ossfuzzDockerFilepath: vscode.Uri,
|
| 658 |
+
wsedit: vscode.WorkspaceEdit,
|
| 659 |
+
wsPath: string,
|
| 660 |
+
baseFolder: string,
|
| 661 |
+
baseName: string,
|
| 662 |
+
isOssFuzz: boolean
|
| 663 |
+
) {
|
| 664 |
+
// Only write to Dockerfile if it doesn't already exist
|
| 665 |
+
// Dockerfile
|
| 666 |
+
if (fs.existsSync(ossfuzzDockerFilepath.path) === false) {
|
| 667 |
+
const dockerfileTemplate =
|
| 668 |
+
getBaseDockerFile('python') +
|
| 669 |
+
`
|
| 670 |
+
RUN python3 -m pip install --upgrade pip
|
| 671 |
+
RUN git clone --depth 1 ${projectGithubRepository} ${projectNameFromRepo}
|
| 672 |
+
WORKDIR ${projectNameFromRepo}
|
| 673 |
+
COPY build.sh *.py $SRC/`;
|
| 674 |
+
|
| 675 |
+
const dockerfileTemplateClusterfuzzLite =
|
| 676 |
+
getBaseDockerFile('python') +
|
| 677 |
+
`
|
| 678 |
+
RUN apt-get update && apt-get install -y make autoconf automake libtool
|
| 679 |
+
|
| 680 |
+
COPY . $SRC/${baseName}
|
| 681 |
+
COPY .clusterfuzzlite/build.sh $SRC/build.sh
|
| 682 |
+
WORKDIR $SRC/${baseName}`;
|
| 683 |
+
|
| 684 |
+
const contentToWrite = isOssFuzz
|
| 685 |
+
? dockerfileTemplate
|
| 686 |
+
: dockerfileTemplateClusterfuzzLite;
|
| 687 |
+
|
| 688 |
+
wsedit.insert(
|
| 689 |
+
ossfuzzDockerFilepath,
|
| 690 |
+
new vscode.Position(0, 0),
|
| 691 |
+
contentToWrite
|
| 692 |
+
);
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
// build.sh
|
| 696 |
+
const ossfuzzBuildFilepath = vscode.Uri.file(
|
| 697 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/build.sh'
|
| 698 |
+
);
|
| 699 |
+
// Only create the build file if it doesn't exist
|
| 700 |
+
if (fs.existsSync(ossfuzzBuildFilepath.path) === false) {
|
| 701 |
+
vscode.window.showInformationMessage(ossfuzzBuildFilepath.toString());
|
| 702 |
+
wsedit.createFile(ossfuzzBuildFilepath, {ignoreIfExists: true});
|
| 703 |
+
const buildTemplate =
|
| 704 |
+
`#!/bin/bash -eu
|
| 705 |
+
` +
|
| 706 |
+
getLicenseHeader() +
|
| 707 |
+
`
|
| 708 |
+
python3 -m pip install .
|
| 709 |
+
|
| 710 |
+
# Build fuzzers (files prefixed with fuzz_) to $OUT
|
| 711 |
+
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
|
| 712 |
+
compile_python_fuzzer $fuzzer
|
| 713 |
+
done`;
|
| 714 |
+
|
| 715 |
+
const buildTemplateClusterfuzzLite = `#!/bin/bash -eu
|
| 716 |
+
python3 -m pip install .
|
| 717 |
+
|
| 718 |
+
# Build fuzzers (files prefixed with fuzz_) to $OUT
|
| 719 |
+
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
|
| 720 |
+
compile_python_fuzzer $fuzzer
|
| 721 |
+
done`;
|
| 722 |
+
|
| 723 |
+
const buildContent = isOssFuzz
|
| 724 |
+
? buildTemplate
|
| 725 |
+
: buildTemplateClusterfuzzLite;
|
| 726 |
+
wsedit.insert(
|
| 727 |
+
ossfuzzBuildFilepath,
|
| 728 |
+
new vscode.Position(0, 0),
|
| 729 |
+
buildContent
|
| 730 |
+
);
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
// project.yaml
|
| 734 |
+
createProjectYamlContent(
|
| 735 |
+
wsedit,
|
| 736 |
+
wsPath,
|
| 737 |
+
baseFolder,
|
| 738 |
+
isOssFuzz,
|
| 739 |
+
projectGithubRepository,
|
| 740 |
+
projectNameFromRepo,
|
| 741 |
+
'python'
|
| 742 |
+
);
|
| 743 |
+
|
| 744 |
+
// Sample template fuzzer
|
| 745 |
+
const sampleFuzzFile = vscode.Uri.file(
|
| 746 |
+
wsPath + '/' + baseFolder + '/' + projectNameFromRepo + '/fuzz_ex1.py'
|
| 747 |
+
);
|
| 748 |
+
if (fs.existsSync(sampleFuzzFile.path) === false) {
|
| 749 |
+
wsedit.createFile(sampleFuzzFile, {ignoreIfExists: true});
|
| 750 |
+
const sampleFuzzFileContents = fuzzTemplate.pythonLangFileInputFuzzer;
|
| 751 |
+
|
| 752 |
+
wsedit.insert(
|
| 753 |
+
sampleFuzzFile,
|
| 754 |
+
new vscode.Position(0, 0),
|
| 755 |
+
sampleFuzzFileContents
|
| 756 |
+
);
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
// README.md
|
|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// 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 |
+
}
|