Add files using upload-large-folder tool
Browse files- local-test-tika-full-01-vuln_7/fuzz-tooling/docs/getting-started/new-project-guide/jvm_lang.md +185 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/docs/getting-started/new-project-guide/python_lang.md +137 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc +0 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/__pycache__/templates.cpython-312.pyc +0 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/README.md +6 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/all.sh +28 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/ci/build.py +292 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/affected_fuzz_targets.py +113 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/build-images.sh +34 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/build_fuzzers_entrypoint.py +60 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/clusterfuzz_deployment.py +385 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/continuous_integration_test.py +88 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/docker.py +127 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/logs.py +25 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/requirements.txt +4 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/run_cifuzz.py +89 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/run_fuzzers_entrypoint.py +97 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/sarif_utils.py +251 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/tools/hold_back_images.py +128 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/infra/uploader/Dockerfile +7 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/.editorconfig +8 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/.eslintignore +1 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/LICENSE +201 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/cifuzz.ts +70 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commandUtils.ts +17 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts +80 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspaceCFLite.ts +49 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdCreateOSSFuzzSetup.ts +28 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdDispatcherGenerateClusterfuzzLite.ts +38 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdDisplayCoverage.ts +71 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdEndToEndCoverage.ts +192 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdFIGetOptimalTargets.ts +21 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdListFuzzers.ts +42 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdRedo.ts +35 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts +167 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFI.ts +24 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFuzzer.ts +83 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetOSSFuzzPath.ts +59 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupCIFuzz.ts +87 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupFI.ts +24 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupOSSFuzz.ts +53 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdTemplate.ts +357 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzer.ts +90 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzerCFLite.ts +89 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/config.ts +37 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/extension.ts +227 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/fuzzIntrospectorHelper.ts +117 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/ossfuzzWrappers.ts +385 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/projectIntegrationHelper.ts +761 -0
- local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/utils.ts +306 -0
local-test-tika-full-01-vuln_7/fuzz-tooling/docs/getting-started/new-project-guide/jvm_lang.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
layout: default
|
| 3 |
+
title: Integrating a Java/JVM project
|
| 4 |
+
parent: Setting up a new project
|
| 5 |
+
grand_parent: Getting started
|
| 6 |
+
nav_order: 4
|
| 7 |
+
permalink: /getting-started/new-project-guide/jvm-lang/
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Integrating a Java/JVM project
|
| 11 |
+
{: .no_toc}
|
| 12 |
+
|
| 13 |
+
- TOC
|
| 14 |
+
{:toc}
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
The process of integrating a project written in Java or any other language
|
| 18 |
+
running on the Java Virtual Machine (JVM) with OSS-Fuzz is very similar to the
|
| 19 |
+
general
|
| 20 |
+
[Setting up a new project]({{ site.baseurl }}/getting-started/new-project-guide/)
|
| 21 |
+
process. The key specifics of integrating a JVM project are outlined below.
|
| 22 |
+
|
| 23 |
+
## Jazzer
|
| 24 |
+
|
| 25 |
+
Java fuzzing in OSS-Fuzz depends on
|
| 26 |
+
[Jazzer](https://github.com/CodeIntelligenceTesting/jazzer), which is
|
| 27 |
+
pre-installed on the OSS-Fuzz base docker images. As Jazzer operates directly
|
| 28 |
+
on the bytecode level, it can be applied to any project written in a JVM-based
|
| 29 |
+
language. More information on how Jazzer fuzz targets look like can be found in
|
| 30 |
+
its
|
| 31 |
+
[README's Usage section](https://github.com/CodeIntelligenceTesting/jazzer#usage).
|
| 32 |
+
|
| 33 |
+
## Project files
|
| 34 |
+
|
| 35 |
+
### Example project
|
| 36 |
+
|
| 37 |
+
We recommend viewing
|
| 38 |
+
[json-sanitizer](https://github.com/google/oss-fuzz/tree/master/projects/json-sanitizer)
|
| 39 |
+
as an example of a simple Java-only fuzzing project. Additional examples,
|
| 40 |
+
including one for a Java project with native dependencies, are part of the
|
| 41 |
+
[java-example](https://github.com/google/oss-fuzz/tree/master/projects/java-example)
|
| 42 |
+
project.
|
| 43 |
+
|
| 44 |
+
### project.yaml
|
| 45 |
+
|
| 46 |
+
The `language` attribute must be specified as follows:
|
| 47 |
+
|
| 48 |
+
```yaml
|
| 49 |
+
language: jvm
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
The only supported fuzzing engine is libFuzzer (`libfuzzer`). So far the only
|
| 53 |
+
supported sanitizers are AddressSanitizer (`address`) and
|
| 54 |
+
UndefinedBehaviorSanitizer (`undefined`). For pure Java projects, specify
|
| 55 |
+
just `address`:
|
| 56 |
+
|
| 57 |
+
```yaml
|
| 58 |
+
fuzzing_engines:
|
| 59 |
+
- libfuzzer
|
| 60 |
+
sanitizers:
|
| 61 |
+
- address
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Dockerfile
|
| 65 |
+
|
| 66 |
+
The Dockerfile should start by `FROM gcr.io/oss-fuzz-base/base-builder-jvm`
|
| 67 |
+
|
| 68 |
+
The OSS-Fuzz base Docker images already come with OpenJDK 15 pre-installed. If
|
| 69 |
+
you need Maven to build your project, you can install it by adding the following
|
| 70 |
+
line to your Dockerfile:
|
| 71 |
+
|
| 72 |
+
```docker
|
| 73 |
+
RUN apt-get update && apt-get install -y maven
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
Apart from this, you should usually not need to do more than to clone the
|
| 77 |
+
project, set a `WORKDIR`, and copy any necessary files, or install any
|
| 78 |
+
project-specific dependencies here as you normally would.
|
| 79 |
+
|
| 80 |
+
### Fuzzers
|
| 81 |
+
|
| 82 |
+
In the simplest case, every fuzzer consists of a single Java file with a
|
| 83 |
+
filename matching `*Fuzzer.java` and no `package` directive. An example fuzz
|
| 84 |
+
target could thus be a file `ExampleFuzzer.java` with contents:
|
| 85 |
+
|
| 86 |
+
```java
|
| 87 |
+
public class ExampleFuzzer {
|
| 88 |
+
public static void fuzzerTestOneInput(byte[] input) {
|
| 89 |
+
...
|
| 90 |
+
// Call a function of the project under test with arguments derived from
|
| 91 |
+
// input and throw an exception if something unwanted happens.
|
| 92 |
+
...
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### build.sh
|
| 98 |
+
|
| 99 |
+
For JVM projects, `build.sh` does need some more significant modifications
|
| 100 |
+
over C/C++ projects. Below is an annotated example build script for a
|
| 101 |
+
Java-only project with single-file fuzz targets as described above:
|
| 102 |
+
|
| 103 |
+
```sh
|
| 104 |
+
# Step 1: Build the project
|
| 105 |
+
|
| 106 |
+
# Build the project .jar as usual, e.g. using Maven.
|
| 107 |
+
mvn package
|
| 108 |
+
# In this example, the project is built with Maven, which typically includes the
|
| 109 |
+
# project version into the name of the packaged .jar file. The version can be
|
| 110 |
+
# obtained as follows:
|
| 111 |
+
CURRENT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
|
| 112 |
+
-Dexpression=project.version -q -DforceStdout)
|
| 113 |
+
# Copy the project .jar into $OUT under a fixed name.
|
| 114 |
+
cp "target/sample-project-$CURRENT_VERSION.jar" $OUT/sample-project.jar
|
| 115 |
+
|
| 116 |
+
# Specify the projects .jar file(s), separated by spaces if there are multiple.
|
| 117 |
+
PROJECT_JARS="sample-project.jar"
|
| 118 |
+
|
| 119 |
+
# Step 2: Build the fuzzers (should not require any changes)
|
| 120 |
+
|
| 121 |
+
# The classpath at build-time includes the project jars in $OUT as well as the
|
| 122 |
+
# Jazzer API.
|
| 123 |
+
BUILD_CLASSPATH=$(echo $PROJECT_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH
|
| 124 |
+
|
| 125 |
+
# All .jar and .class files lie in the same directory as the fuzzer at runtime.
|
| 126 |
+
RUNTIME_CLASSPATH=$(echo $PROJECT_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir
|
| 127 |
+
|
| 128 |
+
for fuzzer in $(find $SRC -name '*Fuzzer.java'); do
|
| 129 |
+
fuzzer_basename=$(basename -s .java $fuzzer)
|
| 130 |
+
javac -cp $BUILD_CLASSPATH $fuzzer
|
| 131 |
+
cp $SRC/$fuzzer_basename.class $OUT/
|
| 132 |
+
|
| 133 |
+
# Create an execution wrapper that executes Jazzer with the correct arguments.
|
| 134 |
+
echo "#!/bin/bash
|
| 135 |
+
# LLVMFuzzerTestOneInput for fuzzer detection.
|
| 136 |
+
this_dir=\$(dirname \"\$0\")
|
| 137 |
+
if [[ \"\$@\" =~ (^| )-runs=[0-9]+($| ) ]]; then
|
| 138 |
+
mem_settings='-Xmx1900m:-Xss900k'
|
| 139 |
+
else
|
| 140 |
+
mem_settings='-Xmx2048m:-Xss1024k'
|
| 141 |
+
fi
|
| 142 |
+
LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \
|
| 143 |
+
\$this_dir/jazzer_driver --agent_path=\$this_dir/jazzer_agent_deploy.jar \
|
| 144 |
+
--cp=$RUNTIME_CLASSPATH \
|
| 145 |
+
--target_class=$fuzzer_basename \
|
| 146 |
+
--jvm_args=\"\$mem_settings:-Djava.awt.headless=true\" \
|
| 147 |
+
\$@" > $OUT/$fuzzer_basename
|
| 148 |
+
chmod +x $OUT/$fuzzer_basename
|
| 149 |
+
done
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
The [java-example](https://github.com/google/oss-fuzz/blob/master/projects/java-example/build.sh)
|
| 153 |
+
project contains an example of a `build.sh` for Java projects with native
|
| 154 |
+
libraries.
|
| 155 |
+
|
| 156 |
+
## FuzzedDataProvider
|
| 157 |
+
|
| 158 |
+
Jazzer provides a `FuzzedDataProvider` that can simplify the task of creating a
|
| 159 |
+
fuzz target by translating the raw input bytes received from the fuzzer into
|
| 160 |
+
useful primitive Java types. Its functionality is similar to
|
| 161 |
+
`FuzzedDataProviders` available in other languages, such as
|
| 162 |
+
[Python](https://github.com/google/atheris#fuzzeddataprovider) and
|
| 163 |
+
[C++](https://github.com/google/fuzzing/blob/master/docs/split-inputs.md).
|
| 164 |
+
|
| 165 |
+
On OSS-Fuzz, the required library is available in the base docker images under
|
| 166 |
+
the path `$JAZZER_API_PATH`, which is added to the classpath by the example
|
| 167 |
+
build script shown above. Locally, the library can be obtained from
|
| 168 |
+
[Maven Central](https://search.maven.org/search?q=g:com.code-intelligence%20a:jazzer-api).
|
| 169 |
+
|
| 170 |
+
A fuzz target using the `FuzzedDataProvider` would look as follows:
|
| 171 |
+
|
| 172 |
+
```java
|
| 173 |
+
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
| 174 |
+
|
| 175 |
+
public class ExampleFuzzer {
|
| 176 |
+
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
|
| 177 |
+
int number = data.consumeInt();
|
| 178 |
+
String string = data.consumeRemainingAsString();
|
| 179 |
+
// ...
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
For a list of convenience methods offered by `FuzzedDataProvider`, consult its
|
| 185 |
+
[javadocs](https://codeintelligencetesting.github.io/jazzer-docs/jazzer-api/com/code_intelligence/jazzer/api/FuzzedDataProvider.html).
|
local-test-tika-full-01-vuln_7/fuzz-tooling/docs/getting-started/new-project-guide/python_lang.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
layout: default
|
| 3 |
+
title: Integrating a Python project
|
| 4 |
+
parent: Setting up a new project
|
| 5 |
+
grand_parent: Getting started
|
| 6 |
+
nav_order: 3
|
| 7 |
+
permalink: /getting-started/new-project-guide/python-lang/
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Integrating a Python project
|
| 11 |
+
{: .no_toc}
|
| 12 |
+
|
| 13 |
+
- TOC
|
| 14 |
+
{:toc}
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
The process of integrating a project written in Python with OSS-Fuzz is very
|
| 19 |
+
similar to the general
|
| 20 |
+
[Setting up a new project]({{ site.baseurl }}/getting-started/new-project-guide/)
|
| 21 |
+
process. The key specifics of integrating a Python project are outlined below.
|
| 22 |
+
|
| 23 |
+
## Atheris
|
| 24 |
+
|
| 25 |
+
Python fuzzing in OSS-Fuzz depends on
|
| 26 |
+
[Atheris](https://github.com/google/atheris). Fuzzers will depend on the
|
| 27 |
+
`atheris` package, and dependencies are pre-installed on the OSS-Fuzz base
|
| 28 |
+
docker images.
|
| 29 |
+
|
| 30 |
+
## Project files
|
| 31 |
+
|
| 32 |
+
### Example project
|
| 33 |
+
|
| 34 |
+
We recommend viewing [ujson](https://github.com/google/oss-fuzz/tree/master/projects/ujson) as an
|
| 35 |
+
example of a simple Python fuzzing project, with both plain-Atheris and
|
| 36 |
+
Atheris + Hypothesis harnesses.
|
| 37 |
+
|
| 38 |
+
### project.yaml
|
| 39 |
+
|
| 40 |
+
The `language` attribute must be specified.
|
| 41 |
+
|
| 42 |
+
```yaml
|
| 43 |
+
language: python
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
The only supported fuzzing engine is libFuzzer (`libfuzzer`). The supported
|
| 47 |
+
sanitizers are AddressSanitizer (`address`) and
|
| 48 |
+
UndefinedBehaviorSanitizer (`undefined`). These must be explicitly specified.
|
| 49 |
+
|
| 50 |
+
```yaml
|
| 51 |
+
fuzzing_engines:
|
| 52 |
+
- libfuzzer
|
| 53 |
+
sanitizers:
|
| 54 |
+
- address
|
| 55 |
+
- undefined
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
### Dockerfile
|
| 59 |
+
|
| 60 |
+
The Dockerfile should start by `FROM gcr.io/oss-fuzz-base/base-builder-python`
|
| 61 |
+
|
| 62 |
+
Because most dependencies are already pre-installed on the images, no
|
| 63 |
+
significant changes are needed in the Dockerfile for Python fuzzing projects.
|
| 64 |
+
You should simply clone the project, set a `WORKDIR`, and copy any necessary
|
| 65 |
+
files, or install any project-specific dependencies here as you normally would.
|
| 66 |
+
|
| 67 |
+
### build.sh
|
| 68 |
+
|
| 69 |
+
For Python projects, `build.sh` does need some more significant modifications
|
| 70 |
+
over normal projects. The following is an annotated example build script,
|
| 71 |
+
explaining why each step is necessary and when they can be omitted.
|
| 72 |
+
|
| 73 |
+
```sh
|
| 74 |
+
# Build and install project (using current CFLAGS, CXXFLAGS). This is required
|
| 75 |
+
# for projects with C extensions so that they're built with the proper flags.
|
| 76 |
+
pip3 install .
|
| 77 |
+
|
| 78 |
+
# Build fuzzers into $OUT. These could be detected in other ways.
|
| 79 |
+
for fuzzer in $(find $SRC -name '*_fuzzer.py'); do
|
| 80 |
+
fuzzer_basename=$(basename -s .py $fuzzer)
|
| 81 |
+
fuzzer_package=${fuzzer_basename}.pkg
|
| 82 |
+
|
| 83 |
+
# To avoid issues with Python version conflicts, or changes in environment
|
| 84 |
+
# over time on the OSS-Fuzz bots, we use pyinstaller to create a standalone
|
| 85 |
+
# package. Though not necessarily required for reproducing issues, this is
|
| 86 |
+
# required to keep fuzzers working properly in OSS-Fuzz.
|
| 87 |
+
pyinstaller --distpath $OUT --onefile --name $fuzzer_package $fuzzer
|
| 88 |
+
|
| 89 |
+
# Create execution wrapper. Atheris requires that certain libraries are
|
| 90 |
+
# preloaded, so this is also done here to ensure compatibility and simplify
|
| 91 |
+
# test case reproduction. Since this helper script is what OSS-Fuzz will
|
| 92 |
+
# actually execute, it is also always required.
|
| 93 |
+
# NOTE: If you are fuzzing python-only code and do not have native C/C++
|
| 94 |
+
# extensions, then remove the LD_PRELOAD line below as preloading sanitizer
|
| 95 |
+
# library is not required and can lead to unexpected startup crashes.
|
| 96 |
+
echo "#!/bin/sh
|
| 97 |
+
# LLVMFuzzerTestOneInput for fuzzer detection.
|
| 98 |
+
this_dir=\$(dirname \"\$0\")
|
| 99 |
+
LD_PRELOAD=\$this_dir/sanitizer_with_fuzzer.so \
|
| 100 |
+
ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \
|
| 101 |
+
\$this_dir/$fuzzer_package \$@" > $OUT/$fuzzer_basename
|
| 102 |
+
chmod +x $OUT/$fuzzer_basename
|
| 103 |
+
done
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
## Hypothesis
|
| 107 |
+
|
| 108 |
+
Using [Hypothesis](https://hypothesis.readthedocs.io/), the Python library for
|
| 109 |
+
[property-based testing](https://hypothesis.works/articles/what-is-property-based-testing/),
|
| 110 |
+
makes it really easy to generate complex inputs - whether in traditional test suites
|
| 111 |
+
or [by using test functions as fuzz harnesses](https://hypothesis.readthedocs.io/en/latest/details.html#use-with-external-fuzzers).
|
| 112 |
+
|
| 113 |
+
> Property based testing is the construction of tests such that, when these tests are fuzzed,
|
| 114 |
+
failures in the test reveal problems with the system under test that could not have been
|
| 115 |
+
revealed by direct fuzzing of that system.
|
| 116 |
+
|
| 117 |
+
We recommend using the [`hypothesis write`](https://hypothesis.readthedocs.io/en/latest/ghostwriter.html)
|
| 118 |
+
command to generate a starter fuzz harness. This "ghostwritten" code may be usable as-is,
|
| 119 |
+
or provide a useful template for writing more specific tests.
|
| 120 |
+
|
| 121 |
+
See [here for the core "strategies"](https://hypothesis.readthedocs.io/en/latest/data.html),
|
| 122 |
+
for arbitrary data, [here for Numpy + Pandas support](https://hypothesis.readthedocs.io/en/latest/numpy.html),
|
| 123 |
+
or [here for a variety of third-party extensions](https://hypothesis.readthedocs.io/en/latest/strategies.html)
|
| 124 |
+
supporting everything from protobufs, to jsonschemas, to networkx graphs or geojson
|
| 125 |
+
or valid Python source code.
|
| 126 |
+
Hypothesis' integrated test-case reduction also makes it trivial to report a canonical minimal
|
| 127 |
+
example for each distinct failure discovered while fuzzing - just run the test function!
|
| 128 |
+
|
| 129 |
+
To use Hypothesis in OSS-Fuzz, install it in your Dockerfile with
|
| 130 |
+
|
| 131 |
+
```shell
|
| 132 |
+
RUN pip3 install hypothesis
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
See [the `ujson` structured fuzzer](https://github.com/google/oss-fuzz/blob/master/projects/ujson/hypothesis_structured_fuzzer.py)
|
| 136 |
+
for an example "polyglot" which can either be run with `pytest` as a standard test function,
|
| 137 |
+
or run with OSS-Fuzz as a fuzz harness.
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/__pycache__/constants.cpython-312.pyc
ADDED
|
Binary file (802 Bytes). View file
|
|
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/__pycache__/templates.cpython-312.pyc
ADDED
|
Binary file (3.04 kB). View file
|
|
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Building all infra images:
|
| 2 |
+
|
| 3 |
+
```bash
|
| 4 |
+
# run from project root
|
| 5 |
+
infra/base-images/all.sh
|
| 6 |
+
```
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/base-images/all.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
docker build --pull -t ghcr.io/aixcc-finals/base-image "$@" infra/base-images/base-image
|
| 19 |
+
docker build -t ghcr.io/aixcc-finals/base-clang "$@" infra/base-images/base-clang
|
| 20 |
+
docker build -t ghcr.io/aixcc-finals/base-builder "$@" infra/base-images/base-builder
|
| 21 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-go "$@" infra/base-images/base-builder-go
|
| 22 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-jvm "$@" infra/base-images/base-builder-jvm
|
| 23 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-python "$@" infra/base-images/base-builder-python
|
| 24 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-rust "$@" infra/base-images/base-builder-rust
|
| 25 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-ruby "$@" infra/base-images/base-builder-ruby
|
| 26 |
+
docker build -t ghcr.io/aixcc-finals/base-builder-swift "$@" infra/base-images/base-builder-swift
|
| 27 |
+
docker build -t ghcr.io/aixcc-finals/base-runner "$@" infra/base-images/base-runner
|
| 28 |
+
docker build -t ghcr.io/aixcc-finals/base-runner-debug "$@" infra/base-images/base-runner-debug
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/ci/build.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# Copyright 2019 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
"""Build modified projects."""
|
| 18 |
+
|
| 19 |
+
from __future__ import print_function
|
| 20 |
+
|
| 21 |
+
import enum
|
| 22 |
+
import os
|
| 23 |
+
import re
|
| 24 |
+
import sys
|
| 25 |
+
import subprocess
|
| 26 |
+
import yaml
|
| 27 |
+
|
| 28 |
+
# pylint: disable=wrong-import-position,import-error
|
| 29 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 30 |
+
|
| 31 |
+
import constants
|
| 32 |
+
|
| 33 |
+
CANARY_PROJECT = 'skcms'
|
| 34 |
+
|
| 35 |
+
DEFAULT_ARCHITECTURES = ['x86_64']
|
| 36 |
+
DEFAULT_ENGINES = ['afl', 'honggfuzz', 'libfuzzer', 'centipede']
|
| 37 |
+
DEFAULT_SANITIZERS = ['address', 'undefined']
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def get_changed_files_output():
|
| 41 |
+
"""Returns the output of a git command that discovers changed files."""
|
| 42 |
+
branch_commit_hash = subprocess.check_output(
|
| 43 |
+
['git', 'merge-base', 'HEAD', 'origin/HEAD']).strip().decode()
|
| 44 |
+
|
| 45 |
+
return subprocess.check_output(
|
| 46 |
+
['git', 'diff', '--name-only', branch_commit_hash + '..']).decode()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def get_modified_buildable_projects():
|
| 50 |
+
"""Returns a list of all the projects modified in this commit that have a
|
| 51 |
+
build.sh file."""
|
| 52 |
+
git_output = get_changed_files_output()
|
| 53 |
+
projects_regex = '.*projects/(?P<name>.*)/.*\n'
|
| 54 |
+
modified_projects = set(re.findall(projects_regex, git_output))
|
| 55 |
+
projects_dir = os.path.join(get_oss_fuzz_root(), 'projects')
|
| 56 |
+
# Filter out projects without Dockerfile files since new projects and reverted
|
| 57 |
+
# projects frequently don't have them. In these cases we don't want Travis's
|
| 58 |
+
# builds to fail.
|
| 59 |
+
modified_buildable_projects = []
|
| 60 |
+
for project in modified_projects:
|
| 61 |
+
if not os.path.exists(os.path.join(projects_dir, project, 'Dockerfile')):
|
| 62 |
+
print('Project {0} does not have Dockerfile. skipping build.'.format(
|
| 63 |
+
project))
|
| 64 |
+
continue
|
| 65 |
+
modified_buildable_projects.append(project)
|
| 66 |
+
return modified_buildable_projects
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def get_oss_fuzz_root():
|
| 70 |
+
"""Get the absolute path of the root of the oss-fuzz checkout."""
|
| 71 |
+
script_path = os.path.realpath(__file__)
|
| 72 |
+
return os.path.abspath(
|
| 73 |
+
os.path.dirname(os.path.dirname(os.path.dirname(script_path))))
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def execute_helper_command(helper_command):
|
| 77 |
+
"""Execute |helper_command| using helper.py."""
|
| 78 |
+
root = get_oss_fuzz_root()
|
| 79 |
+
script_path = os.path.join(root, 'infra', 'helper.py')
|
| 80 |
+
command = ['python', script_path] + helper_command
|
| 81 |
+
print('Running command: %s' % ' '.join(command))
|
| 82 |
+
subprocess.check_call(command)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def build_fuzzers(project, engine, sanitizer, architecture):
|
| 86 |
+
"""Execute helper.py's build_fuzzers command on |project|. Build the fuzzers
|
| 87 |
+
with |engine| and |sanitizer| for |architecture|."""
|
| 88 |
+
execute_helper_command([
|
| 89 |
+
'build_fuzzers', project, '--engine', engine, '--sanitizer', sanitizer,
|
| 90 |
+
'--architecture', architecture
|
| 91 |
+
])
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def check_build(project, engine, sanitizer, architecture):
|
| 95 |
+
"""Execute helper.py's check_build command on |project|, assuming it was most
|
| 96 |
+
recently built with |engine| and |sanitizer| for |architecture|."""
|
| 97 |
+
execute_helper_command([
|
| 98 |
+
'check_build', project, '--engine', engine, '--sanitizer', sanitizer,
|
| 99 |
+
'--architecture', architecture
|
| 100 |
+
])
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def should_build_coverage(project_yaml):
|
| 104 |
+
"""Returns True if a coverage build should be done based on project.yaml
|
| 105 |
+
contents."""
|
| 106 |
+
# Enable coverage builds on projects that use engines. Those that don't use
|
| 107 |
+
# engines shouldn't get coverage builds.
|
| 108 |
+
engines = project_yaml.get('fuzzing_engines', DEFAULT_ENGINES)
|
| 109 |
+
engineless = 'none' in engines
|
| 110 |
+
if engineless:
|
| 111 |
+
assert_message = ('Forbidden to specify multiple engines for '
|
| 112 |
+
'"fuzzing_engines" if "none" is specified.')
|
| 113 |
+
assert len(engines) == 1, assert_message
|
| 114 |
+
return False
|
| 115 |
+
if 'wycheproof' in engines:
|
| 116 |
+
return False
|
| 117 |
+
|
| 118 |
+
language = project_yaml.get('language')
|
| 119 |
+
if language not in constants.LANGUAGES_WITH_COVERAGE_SUPPORT:
|
| 120 |
+
print(('Project is written in "{language}", '
|
| 121 |
+
'coverage is not supported yet.').format(language=language))
|
| 122 |
+
return False
|
| 123 |
+
|
| 124 |
+
return True
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def flatten_options(option_list):
|
| 128 |
+
"""Generator that flattens |option_list| (a list of sanitizers, architectures
|
| 129 |
+
or fuzzing engines) by returning each element in the list that isn't a
|
| 130 |
+
dictionary. For elements that are dictionaries, the sole key is returned."""
|
| 131 |
+
result = []
|
| 132 |
+
for option in option_list:
|
| 133 |
+
if isinstance(option, dict):
|
| 134 |
+
keys = list(option.keys())
|
| 135 |
+
assert len(keys) == 1
|
| 136 |
+
result.append(keys[0])
|
| 137 |
+
continue
|
| 138 |
+
result.append(option)
|
| 139 |
+
print(result)
|
| 140 |
+
return result
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def should_build(project_yaml):
|
| 144 |
+
"""Returns True on if the build specified is enabled in the project.yaml."""
|
| 145 |
+
|
| 146 |
+
if os.getenv('SANITIZER') == 'coverage':
|
| 147 |
+
# This assumes we only do coverage builds with libFuzzer on x86_64.
|
| 148 |
+
return should_build_coverage(project_yaml)
|
| 149 |
+
|
| 150 |
+
def is_enabled(env_var, yaml_name, defaults):
|
| 151 |
+
"""Is the value of |env_var| enabled in |project_yaml| (in the |yaml_name|
|
| 152 |
+
section)? Uses |defaults| if |yaml_name| section is unspecified."""
|
| 153 |
+
return os.getenv(env_var) in flatten_options(
|
| 154 |
+
project_yaml.get(yaml_name, defaults))
|
| 155 |
+
|
| 156 |
+
return (is_enabled('ENGINE', 'fuzzing_engines', DEFAULT_ENGINES) and
|
| 157 |
+
is_enabled('SANITIZER', 'sanitizers', DEFAULT_SANITIZERS) and
|
| 158 |
+
is_enabled('ARCHITECTURE', 'architectures', DEFAULT_ARCHITECTURES))
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def build_project(project):
|
| 162 |
+
"""Do the build of |project| that is specified by the environment variables -
|
| 163 |
+
SANITIZER, ENGINE, and ARCHITECTURE."""
|
| 164 |
+
root = get_oss_fuzz_root()
|
| 165 |
+
project_yaml_path = os.path.join(root, 'projects', project, 'project.yaml')
|
| 166 |
+
with open(project_yaml_path) as file_handle:
|
| 167 |
+
project_yaml = yaml.safe_load(file_handle)
|
| 168 |
+
|
| 169 |
+
if project_yaml.get('disabled', False):
|
| 170 |
+
print('Project {0} is disabled, skipping build.'.format(project))
|
| 171 |
+
return
|
| 172 |
+
|
| 173 |
+
engine = os.getenv('ENGINE')
|
| 174 |
+
sanitizer = os.getenv('SANITIZER')
|
| 175 |
+
architecture = os.getenv('ARCHITECTURE')
|
| 176 |
+
|
| 177 |
+
if not should_build(project_yaml):
|
| 178 |
+
print(('Specified build: engine: {0}, sanitizer: {1}, architecture: {2} '
|
| 179 |
+
'not enabled for this project: {3}. Skipping build.').format(
|
| 180 |
+
engine, sanitizer, architecture, project))
|
| 181 |
+
|
| 182 |
+
return
|
| 183 |
+
|
| 184 |
+
print('Building project', project)
|
| 185 |
+
build_fuzzers(project, engine, sanitizer, architecture)
|
| 186 |
+
|
| 187 |
+
run_tests = project_yaml.get('run_tests', True)
|
| 188 |
+
if engine != 'none' and sanitizer != 'coverage' and run_tests:
|
| 189 |
+
check_build(project, engine, sanitizer, architecture)
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
class BuildModifiedProjectsResult(enum.Enum):
|
| 193 |
+
"""Enum containing the return values of build_modified_projects()."""
|
| 194 |
+
NONE_BUILT = 0
|
| 195 |
+
BUILD_SUCCESS = 1
|
| 196 |
+
BUILD_FAIL = 2
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def build_modified_projects():
|
| 200 |
+
"""Build modified projects. Returns BuildModifiedProjectsResult.NONE_BUILT if
|
| 201 |
+
no builds were attempted. Returns BuildModifiedProjectsResult.BUILD_SUCCESS if
|
| 202 |
+
all attempts succeed, otherwise returns
|
| 203 |
+
BuildModifiedProjectsResult.BUILD_FAIL."""
|
| 204 |
+
projects = get_modified_buildable_projects()
|
| 205 |
+
if not projects:
|
| 206 |
+
return BuildModifiedProjectsResult.NONE_BUILT
|
| 207 |
+
|
| 208 |
+
failed_projects = []
|
| 209 |
+
for project in projects:
|
| 210 |
+
try:
|
| 211 |
+
build_project(project)
|
| 212 |
+
except subprocess.CalledProcessError:
|
| 213 |
+
failed_projects.append(project)
|
| 214 |
+
|
| 215 |
+
if failed_projects:
|
| 216 |
+
print('Failed projects:', ' '.join(failed_projects))
|
| 217 |
+
return BuildModifiedProjectsResult.BUILD_FAIL
|
| 218 |
+
|
| 219 |
+
return BuildModifiedProjectsResult.BUILD_SUCCESS
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def is_infra_changed():
|
| 223 |
+
"""Returns True if the infra directory was changed."""
|
| 224 |
+
git_output = get_changed_files_output()
|
| 225 |
+
infra_code_regex = '.*infra/.*\n'
|
| 226 |
+
return re.search(infra_code_regex, git_output) is not None
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def build_base_images():
|
| 230 |
+
"""Builds base images."""
|
| 231 |
+
# TODO(jonathanmetzman): Investigate why caching fails so often and
|
| 232 |
+
# when we improve it, build base-clang as well. Also, move this function
|
| 233 |
+
# to a helper command when we can support base-clang.
|
| 234 |
+
execute_helper_command(['pull_images'])
|
| 235 |
+
images = [
|
| 236 |
+
'base-image',
|
| 237 |
+
'base-builder',
|
| 238 |
+
'base-builder-go',
|
| 239 |
+
'base-builder-javascript',
|
| 240 |
+
'base-builder-jvm',
|
| 241 |
+
'base-builder-python',
|
| 242 |
+
'base-builder-rust',
|
| 243 |
+
'base-builder-swift',
|
| 244 |
+
'base-builder-ruby',
|
| 245 |
+
'base-runner',
|
| 246 |
+
]
|
| 247 |
+
for image in images:
|
| 248 |
+
try:
|
| 249 |
+
execute_helper_command(['build_image', image, '--no-pull', '--cache'])
|
| 250 |
+
except subprocess.CalledProcessError:
|
| 251 |
+
return 1
|
| 252 |
+
|
| 253 |
+
return 0
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def build_canary_project():
|
| 257 |
+
"""Builds a specific project when infra/ is changed to verify that infra/
|
| 258 |
+
changes don't break things. Returns False if build was attempted but
|
| 259 |
+
failed."""
|
| 260 |
+
|
| 261 |
+
try:
|
| 262 |
+
build_project('skcms')
|
| 263 |
+
except subprocess.CalledProcessError:
|
| 264 |
+
return False
|
| 265 |
+
|
| 266 |
+
return True
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def main():
|
| 270 |
+
"""Build modified projects or canary project."""
|
| 271 |
+
os.environ['OSS_FUZZ_CI'] = '1'
|
| 272 |
+
infra_changed = is_infra_changed()
|
| 273 |
+
if infra_changed:
|
| 274 |
+
print('Pulling and building base images first.')
|
| 275 |
+
if build_base_images():
|
| 276 |
+
return 1
|
| 277 |
+
|
| 278 |
+
result = build_modified_projects()
|
| 279 |
+
if result == BuildModifiedProjectsResult.BUILD_FAIL:
|
| 280 |
+
return 1
|
| 281 |
+
|
| 282 |
+
# It's unnecessary to build the canary if we've built any projects already.
|
| 283 |
+
no_projects_built = result == BuildModifiedProjectsResult.NONE_BUILT
|
| 284 |
+
should_build_canary = no_projects_built and infra_changed
|
| 285 |
+
if should_build_canary and not build_canary_project():
|
| 286 |
+
return 1
|
| 287 |
+
|
| 288 |
+
return 0
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
if __name__ == '__main__':
|
| 292 |
+
sys.exit(main())
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/affected_fuzz_targets.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Module for dealing with fuzz targets affected by the change-under-test
|
| 15 |
+
(CUT)."""
|
| 16 |
+
import logging
|
| 17 |
+
import os
|
| 18 |
+
import sys
|
| 19 |
+
|
| 20 |
+
# pylint: disable=wrong-import-position,import-error
|
| 21 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 22 |
+
import utils
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def remove_unaffected_fuzz_targets(clusterfuzz_deployment, out_dir,
|
| 26 |
+
files_changed, repo_path):
|
| 27 |
+
"""Removes all non affected fuzz targets in the out directory.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
clusterfuzz_deployment: The ClusterFuzz deployment object.
|
| 31 |
+
out_dir: The location of the fuzz target binaries.
|
| 32 |
+
files_changed: A list of files changed compared to HEAD.
|
| 33 |
+
repo_path: The location of the OSS-Fuzz repo in the docker image.
|
| 34 |
+
|
| 35 |
+
This function will not delete fuzz targets unless it knows that the fuzz
|
| 36 |
+
targets are unaffected. For example, this means that fuzz targets which don't
|
| 37 |
+
have coverage data on will not be deleted.
|
| 38 |
+
"""
|
| 39 |
+
if not files_changed:
|
| 40 |
+
# Don't remove any fuzz targets if there is no difference from HEAD.
|
| 41 |
+
logging.info('No files changed compared to HEAD.')
|
| 42 |
+
return
|
| 43 |
+
|
| 44 |
+
logging.info('Files changed in PR: %s', files_changed)
|
| 45 |
+
|
| 46 |
+
fuzz_target_paths = utils.get_fuzz_targets(out_dir)
|
| 47 |
+
if not fuzz_target_paths:
|
| 48 |
+
# Nothing to remove.
|
| 49 |
+
logging.error('No fuzz targets found in out dir.')
|
| 50 |
+
return
|
| 51 |
+
|
| 52 |
+
coverage = clusterfuzz_deployment.get_coverage(repo_path)
|
| 53 |
+
if not coverage:
|
| 54 |
+
# Don't remove any fuzz targets unless we have data.
|
| 55 |
+
logging.error('Could not find latest coverage report.')
|
| 56 |
+
return
|
| 57 |
+
|
| 58 |
+
affected_fuzz_targets = get_affected_fuzz_targets(coverage, fuzz_target_paths,
|
| 59 |
+
files_changed)
|
| 60 |
+
|
| 61 |
+
if not affected_fuzz_targets:
|
| 62 |
+
logging.info('No affected fuzz targets detected, keeping all as fallback.')
|
| 63 |
+
return
|
| 64 |
+
|
| 65 |
+
logging.info('Using affected fuzz targets: %s.', affected_fuzz_targets)
|
| 66 |
+
unaffected_fuzz_targets = set(fuzz_target_paths) - affected_fuzz_targets
|
| 67 |
+
logging.info('Removing unaffected fuzz targets: %s.', unaffected_fuzz_targets)
|
| 68 |
+
|
| 69 |
+
# Remove all the targets that are not affected.
|
| 70 |
+
for fuzz_target_path in unaffected_fuzz_targets:
|
| 71 |
+
try:
|
| 72 |
+
os.remove(fuzz_target_path)
|
| 73 |
+
except OSError as error:
|
| 74 |
+
logging.error('%s occurred while removing file %s', error,
|
| 75 |
+
fuzz_target_path)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def is_fuzz_target_affected(coverage, fuzz_target_path, files_changed):
|
| 79 |
+
"""Returns True if a fuzz target (|fuzz_target_path|) is affected by
|
| 80 |
+
|files_changed|."""
|
| 81 |
+
fuzz_target = os.path.basename(fuzz_target_path)
|
| 82 |
+
covered_files = coverage.get_files_covered_by_target(fuzz_target)
|
| 83 |
+
if not covered_files:
|
| 84 |
+
# Assume a fuzz target is affected if we can't get its coverage from
|
| 85 |
+
# OSS-Fuzz.
|
| 86 |
+
# TODO(metzman): Figure out what we should do if covered_files is [].
|
| 87 |
+
# Should we act as if we couldn't get the coverage?
|
| 88 |
+
logging.info('Could not get coverage for %s. Treating as affected.',
|
| 89 |
+
fuzz_target)
|
| 90 |
+
return True
|
| 91 |
+
|
| 92 |
+
covered_files = [
|
| 93 |
+
os.path.normpath(covered_file) for covered_file in covered_files
|
| 94 |
+
]
|
| 95 |
+
logging.info('Fuzz target %s is affected by: %s', fuzz_target, covered_files)
|
| 96 |
+
for filename in files_changed:
|
| 97 |
+
if filename in covered_files:
|
| 98 |
+
logging.info('Fuzz target %s is affected by changed file: %s',
|
| 99 |
+
fuzz_target, filename)
|
| 100 |
+
return True
|
| 101 |
+
|
| 102 |
+
logging.info('Fuzz target %s is not affected.', fuzz_target)
|
| 103 |
+
return False
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def get_affected_fuzz_targets(coverage, fuzz_target_paths, files_changed):
|
| 107 |
+
"""Returns a list of paths of affected targets."""
|
| 108 |
+
affected_fuzz_targets = set()
|
| 109 |
+
for fuzz_target_path in fuzz_target_paths:
|
| 110 |
+
if is_fuzz_target_affected(coverage, fuzz_target_path, files_changed):
|
| 111 |
+
affected_fuzz_targets.add(fuzz_target_path)
|
| 112 |
+
|
| 113 |
+
return affected_fuzz_targets
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/build-images.sh
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#! /bin/bash -eux
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
# Script for building the docker images for cifuzz.
|
| 17 |
+
|
| 18 |
+
CIFUZZ_DIR=$(dirname "$0")
|
| 19 |
+
CIFUZZ_DIR=$(realpath $CIFUZZ_DIR)
|
| 20 |
+
INFRA_DIR=$(realpath $CIFUZZ_DIR/..)
|
| 21 |
+
OSS_FUZZ_ROOT=$(realpath $INFRA_DIR/..)
|
| 22 |
+
|
| 23 |
+
# Build cifuzz-base.
|
| 24 |
+
docker build --tag ghcr.io/aixcc-finals/cifuzz-base --file $CIFUZZ_DIR/cifuzz-base/Dockerfile $OSS_FUZZ_ROOT
|
| 25 |
+
|
| 26 |
+
# Build run-fuzzers and build-fuzzers images.
|
| 27 |
+
docker build \
|
| 28 |
+
--tag ghcr.io/aixcc-finals/clusterfuzzlite-build-fuzzers-test:v1 \
|
| 29 |
+
--tag ghcr.io/aixcc-finals/clusterfuzzlite-build-fuzzers:v1 \
|
| 30 |
+
--file $INFRA_DIR/build_fuzzers.Dockerfile $INFRA_DIR
|
| 31 |
+
docker build \
|
| 32 |
+
--tag ghcr.io/aixcc-finals/clusterfuzzlite-run-fuzzers:v1 \
|
| 33 |
+
--tag ghcr.io/aixcc-finals/clusterfuzzlite-run-fuzzers-test:v1 \
|
| 34 |
+
--file $INFRA_DIR/run_fuzzers.Dockerfile $INFRA_DIR
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/build_fuzzers_entrypoint.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Builds a specific OSS-Fuzz project's fuzzers for CI tools."""
|
| 15 |
+
import logging
|
| 16 |
+
import sys
|
| 17 |
+
|
| 18 |
+
import build_fuzzers
|
| 19 |
+
import logs
|
| 20 |
+
import config_utils
|
| 21 |
+
|
| 22 |
+
# pylint: disable=c-extension-no-member
|
| 23 |
+
# pylint gets confused because of the relative import of cifuzz.
|
| 24 |
+
|
| 25 |
+
logs.init()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def build_fuzzers_entrypoint():
|
| 29 |
+
"""Builds OSS-Fuzz project's fuzzers for CI tools."""
|
| 30 |
+
config = config_utils.BuildFuzzersConfig()
|
| 31 |
+
|
| 32 |
+
if config.dry_run:
|
| 33 |
+
# Sets the default return code on error to success.
|
| 34 |
+
returncode = 0
|
| 35 |
+
else:
|
| 36 |
+
# The default return code when an error occurs.
|
| 37 |
+
returncode = 1
|
| 38 |
+
|
| 39 |
+
if not build_fuzzers.build_fuzzers(config):
|
| 40 |
+
logging.error('Error building fuzzers for (commit: %s, pr_ref: %s).',
|
| 41 |
+
config.git_sha, config.pr_ref)
|
| 42 |
+
return returncode
|
| 43 |
+
|
| 44 |
+
return 0
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def main():
|
| 48 |
+
"""Builds OSS-Fuzz project's fuzzers for CI tools.
|
| 49 |
+
|
| 50 |
+
Note: The resulting fuzz target binaries of this build are placed in
|
| 51 |
+
the directory: ${GITHUB_WORKSPACE}/out
|
| 52 |
+
|
| 53 |
+
Returns:
|
| 54 |
+
0 on success or nonzero on failure.
|
| 55 |
+
"""
|
| 56 |
+
return build_fuzzers_entrypoint()
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == '__main__':
|
| 60 |
+
sys.exit(main())
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/clusterfuzz_deployment.py
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Module for interacting with the ClusterFuzz deployment."""
|
| 15 |
+
import logging
|
| 16 |
+
import os
|
| 17 |
+
import sys
|
| 18 |
+
import urllib.error
|
| 19 |
+
import urllib.request
|
| 20 |
+
|
| 21 |
+
import config_utils
|
| 22 |
+
import continuous_integration
|
| 23 |
+
import filestore_utils
|
| 24 |
+
import http_utils
|
| 25 |
+
import get_coverage
|
| 26 |
+
import repo_manager
|
| 27 |
+
|
| 28 |
+
# pylint: disable=wrong-import-position,import-error
|
| 29 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 30 |
+
import utils
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class BaseClusterFuzzDeployment:
|
| 34 |
+
"""Base class for ClusterFuzz deployments."""
|
| 35 |
+
|
| 36 |
+
def __init__(self, config, workspace):
|
| 37 |
+
self.config = config
|
| 38 |
+
self.workspace = workspace
|
| 39 |
+
self.ci_system = continuous_integration.get_ci(config)
|
| 40 |
+
|
| 41 |
+
def download_latest_build(self):
|
| 42 |
+
"""Downloads the latest build from ClusterFuzz.
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
A path to where the OSS-Fuzz build was stored, or None if it wasn't.
|
| 46 |
+
"""
|
| 47 |
+
raise NotImplementedError('Child class must implement method.')
|
| 48 |
+
|
| 49 |
+
def upload_build(self, commit):
|
| 50 |
+
"""Uploads the build with the given commit sha to the filestore."""
|
| 51 |
+
raise NotImplementedError('Child class must implement method.')
|
| 52 |
+
|
| 53 |
+
def download_corpus(self, target_name, corpus_dir):
|
| 54 |
+
"""Downloads the corpus for |target_name| from ClusterFuzz to |corpus_dir|.
|
| 55 |
+
|
| 56 |
+
Returns:
|
| 57 |
+
A path to where the OSS-Fuzz build was stored, or None if it wasn't.
|
| 58 |
+
"""
|
| 59 |
+
raise NotImplementedError('Child class must implement method.')
|
| 60 |
+
|
| 61 |
+
def upload_crashes(self):
|
| 62 |
+
"""Uploads crashes in |crashes_dir| to filestore."""
|
| 63 |
+
raise NotImplementedError('Child class must implement method.')
|
| 64 |
+
|
| 65 |
+
def upload_corpus(self, target_name, corpus_dir, replace=False): # pylint: disable=no-self-use,unused-argument
|
| 66 |
+
"""Uploads the corpus for |target_name| to filestore."""
|
| 67 |
+
raise NotImplementedError('Child class must implement method.')
|
| 68 |
+
|
| 69 |
+
def upload_coverage(self):
|
| 70 |
+
"""Uploads the coverage report to the filestore."""
|
| 71 |
+
raise NotImplementedError('Child class must implement method.')
|
| 72 |
+
|
| 73 |
+
def get_coverage(self, repo_path):
|
| 74 |
+
"""Returns the project coverage object for the project."""
|
| 75 |
+
raise NotImplementedError('Child class must implement method.')
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def _make_empty_dir_if_nonexistent(path):
|
| 79 |
+
"""Makes an empty directory at |path| if it does not exist."""
|
| 80 |
+
os.makedirs(path, exist_ok=True)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class ClusterFuzzLite(BaseClusterFuzzDeployment):
|
| 84 |
+
"""Class representing a deployment of ClusterFuzzLite."""
|
| 85 |
+
|
| 86 |
+
COVERAGE_NAME = 'latest'
|
| 87 |
+
LATEST_BUILD_WINDOW = 3
|
| 88 |
+
|
| 89 |
+
def __init__(self, config, workspace):
|
| 90 |
+
super().__init__(config, workspace)
|
| 91 |
+
self.filestore = filestore_utils.get_filestore(self.config)
|
| 92 |
+
|
| 93 |
+
def download_latest_build(self):
|
| 94 |
+
if os.path.exists(self.workspace.clusterfuzz_build):
|
| 95 |
+
# This path is necessary because download_latest_build can be called
|
| 96 |
+
# multiple times.That is the case because it is called only when we need
|
| 97 |
+
# to see if a bug is novel, i.e. until we want to check a bug is novel we
|
| 98 |
+
# don't want to waste time calling this, but therefore this method can be
|
| 99 |
+
# called if multiple bugs are found.
|
| 100 |
+
return self.workspace.clusterfuzz_build
|
| 101 |
+
|
| 102 |
+
repo_dir = self.ci_system.repo_dir
|
| 103 |
+
if not repo_dir:
|
| 104 |
+
raise RuntimeError('Repo checkout does not exist.')
|
| 105 |
+
|
| 106 |
+
_make_empty_dir_if_nonexistent(self.workspace.clusterfuzz_build)
|
| 107 |
+
repo = repo_manager.RepoManager(repo_dir)
|
| 108 |
+
|
| 109 |
+
diff_base = self.ci_system.get_diff_base()
|
| 110 |
+
if not diff_base:
|
| 111 |
+
diff_base = 'HEAD^'
|
| 112 |
+
|
| 113 |
+
# Builds are stored by commit, so try the latest |LATEST_BUILD_WINDOW|
|
| 114 |
+
# commits before the current diff base.
|
| 115 |
+
# TODO(ochang): If API usage becomes an issue, this can be optimized by the
|
| 116 |
+
# filestore accepting a list of filenames to try.
|
| 117 |
+
try:
|
| 118 |
+
# TODO(metzman): Why do we default to 'origin', we should avoid going down
|
| 119 |
+
# this path entirely and not need to catch an exception.
|
| 120 |
+
commit_list = repo.get_commit_list(diff_base,
|
| 121 |
+
limit=self.LATEST_BUILD_WINDOW)
|
| 122 |
+
except ValueError as error:
|
| 123 |
+
logging.error('Can\'t get commit list: %s', error)
|
| 124 |
+
return None
|
| 125 |
+
|
| 126 |
+
for old_commit in commit_list:
|
| 127 |
+
logging.info('Trying to downloading previous build %s.', old_commit)
|
| 128 |
+
build_name = self._get_build_name(old_commit)
|
| 129 |
+
try:
|
| 130 |
+
if self.filestore.download_build(build_name,
|
| 131 |
+
self.workspace.clusterfuzz_build):
|
| 132 |
+
logging.info('Done downloading previous build.')
|
| 133 |
+
return self.workspace.clusterfuzz_build
|
| 134 |
+
|
| 135 |
+
logging.info('Build for %s does not exist.', old_commit)
|
| 136 |
+
except Exception as err: # pylint: disable=broad-except
|
| 137 |
+
logging.error('Could not download build for %s because of: %s',
|
| 138 |
+
old_commit, err)
|
| 139 |
+
|
| 140 |
+
return None
|
| 141 |
+
|
| 142 |
+
def download_corpus(self, target_name, corpus_dir):
|
| 143 |
+
_make_empty_dir_if_nonexistent(corpus_dir)
|
| 144 |
+
logging.info('Downloading corpus for %s to %s.', target_name, corpus_dir)
|
| 145 |
+
corpus_name = self._get_corpus_name(target_name)
|
| 146 |
+
try:
|
| 147 |
+
self.filestore.download_corpus(corpus_name, corpus_dir)
|
| 148 |
+
logging.info('Done downloading corpus. Contains %d elements.',
|
| 149 |
+
len(os.listdir(corpus_dir)))
|
| 150 |
+
except Exception as err: # pylint: disable=broad-except
|
| 151 |
+
logging.error('Failed to download corpus for target: %s. Error: %s',
|
| 152 |
+
target_name, str(err))
|
| 153 |
+
return corpus_dir
|
| 154 |
+
|
| 155 |
+
def _get_build_name(self, name):
|
| 156 |
+
return f'{self.config.sanitizer}-{name}'
|
| 157 |
+
|
| 158 |
+
def _get_corpus_name(self, target_name): # pylint: disable=no-self-use
|
| 159 |
+
"""Returns the name of the corpus artifact."""
|
| 160 |
+
return target_name
|
| 161 |
+
|
| 162 |
+
def upload_corpus(self, target_name, corpus_dir, replace=False):
|
| 163 |
+
"""Upload the corpus produced by |target_name|."""
|
| 164 |
+
logging.info('Uploading corpus in %s for %s.', corpus_dir, target_name)
|
| 165 |
+
name = self._get_corpus_name(target_name)
|
| 166 |
+
try:
|
| 167 |
+
self.filestore.upload_corpus(name, corpus_dir, replace=replace)
|
| 168 |
+
logging.info('Done uploading corpus.')
|
| 169 |
+
except Exception as err: # pylint: disable=broad-except
|
| 170 |
+
logging.error('Failed to upload corpus for target: %s. Error: %s.',
|
| 171 |
+
target_name, err)
|
| 172 |
+
|
| 173 |
+
def upload_build(self, commit):
|
| 174 |
+
"""Upload the build produced by CIFuzz as the latest build."""
|
| 175 |
+
logging.info('Uploading latest build in %s.', self.workspace.out)
|
| 176 |
+
build_name = self._get_build_name(commit)
|
| 177 |
+
try:
|
| 178 |
+
result = self.filestore.upload_build(build_name, self.workspace.out)
|
| 179 |
+
logging.info('Done uploading latest build.')
|
| 180 |
+
return result
|
| 181 |
+
except Exception as err: # pylint: disable=broad-except
|
| 182 |
+
logging.error('Failed to upload latest build: %s. Error: %s',
|
| 183 |
+
self.workspace.out, err)
|
| 184 |
+
|
| 185 |
+
def upload_crashes(self):
|
| 186 |
+
"""Uploads crashes."""
|
| 187 |
+
artifact_dirs = os.listdir(self.workspace.artifacts)
|
| 188 |
+
if not artifact_dirs:
|
| 189 |
+
logging.info('No crashes in %s. Not uploading.', self.workspace.artifacts)
|
| 190 |
+
return
|
| 191 |
+
|
| 192 |
+
for crash_target in artifact_dirs:
|
| 193 |
+
artifact_dir = os.path.join(self.workspace.artifacts, crash_target)
|
| 194 |
+
if not os.path.isdir(artifact_dir):
|
| 195 |
+
logging.warning('%s is not an expected artifact directory, skipping.',
|
| 196 |
+
crash_target)
|
| 197 |
+
continue
|
| 198 |
+
|
| 199 |
+
logging.info('Uploading crashes in %s.', artifact_dir)
|
| 200 |
+
try:
|
| 201 |
+
self.filestore.upload_crashes(crash_target, artifact_dir)
|
| 202 |
+
logging.info('Done uploading crashes.')
|
| 203 |
+
except Exception as err: # pylint: disable=broad-except
|
| 204 |
+
logging.error('Failed to upload crashes. Error: %s', err)
|
| 205 |
+
|
| 206 |
+
def upload_coverage(self):
|
| 207 |
+
"""Uploads the coverage report to the filestore."""
|
| 208 |
+
self.filestore.upload_coverage(self.COVERAGE_NAME,
|
| 209 |
+
self.workspace.coverage_report)
|
| 210 |
+
|
| 211 |
+
def get_coverage(self, repo_path):
|
| 212 |
+
"""Returns the project coverage object for the project."""
|
| 213 |
+
_make_empty_dir_if_nonexistent(self.workspace.clusterfuzz_coverage)
|
| 214 |
+
try:
|
| 215 |
+
if not self.filestore.download_coverage(
|
| 216 |
+
self.COVERAGE_NAME, self.workspace.clusterfuzz_coverage):
|
| 217 |
+
logging.error('Could not download coverage.')
|
| 218 |
+
return None
|
| 219 |
+
return get_coverage.FilesystemCoverage(
|
| 220 |
+
repo_path, self.workspace.clusterfuzz_coverage)
|
| 221 |
+
except Exception as err: # pylint: disable=broad-except
|
| 222 |
+
logging.error('Could not get coverage: %s.', err)
|
| 223 |
+
return None
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
class OSSFuzz(BaseClusterFuzzDeployment):
|
| 227 |
+
"""The OSS-Fuzz ClusterFuzz deployment."""
|
| 228 |
+
|
| 229 |
+
# Location of clusterfuzz builds on GCS.
|
| 230 |
+
CLUSTERFUZZ_BUILDS = 'clusterfuzz-builds'
|
| 231 |
+
|
| 232 |
+
# Zip file name containing the corpus.
|
| 233 |
+
CORPUS_ZIP_NAME = 'public.zip'
|
| 234 |
+
|
| 235 |
+
def get_latest_build_name(self):
|
| 236 |
+
"""Gets the name of the latest OSS-Fuzz build of a project.
|
| 237 |
+
|
| 238 |
+
Returns:
|
| 239 |
+
A string with the latest build version or None.
|
| 240 |
+
"""
|
| 241 |
+
version_file = (
|
| 242 |
+
f'{self.config.oss_fuzz_project_name}-{self.config.sanitizer}'
|
| 243 |
+
'-latest.version')
|
| 244 |
+
version_url = utils.url_join(utils.GCS_BASE_URL, self.CLUSTERFUZZ_BUILDS,
|
| 245 |
+
self.config.oss_fuzz_project_name,
|
| 246 |
+
version_file)
|
| 247 |
+
try:
|
| 248 |
+
response = urllib.request.urlopen(version_url)
|
| 249 |
+
except urllib.error.HTTPError:
|
| 250 |
+
logging.error('Error getting latest build version for %s from: %s.',
|
| 251 |
+
self.config.oss_fuzz_project_name, version_url)
|
| 252 |
+
return None
|
| 253 |
+
return response.read().decode()
|
| 254 |
+
|
| 255 |
+
def download_latest_build(self):
|
| 256 |
+
"""Downloads the latest OSS-Fuzz build from GCS.
|
| 257 |
+
|
| 258 |
+
Returns:
|
| 259 |
+
A path to where the OSS-Fuzz build was stored, or None if it wasn't.
|
| 260 |
+
"""
|
| 261 |
+
if os.path.exists(self.workspace.clusterfuzz_build):
|
| 262 |
+
# This function can be called multiple times, don't download the build
|
| 263 |
+
# again.
|
| 264 |
+
return self.workspace.clusterfuzz_build
|
| 265 |
+
|
| 266 |
+
_make_empty_dir_if_nonexistent(self.workspace.clusterfuzz_build)
|
| 267 |
+
|
| 268 |
+
latest_build_name = self.get_latest_build_name()
|
| 269 |
+
if not latest_build_name:
|
| 270 |
+
return None
|
| 271 |
+
|
| 272 |
+
logging.info('Downloading latest build.')
|
| 273 |
+
oss_fuzz_build_url = utils.url_join(utils.GCS_BASE_URL,
|
| 274 |
+
self.CLUSTERFUZZ_BUILDS,
|
| 275 |
+
self.config.oss_fuzz_project_name,
|
| 276 |
+
latest_build_name)
|
| 277 |
+
if http_utils.download_and_unpack_zip(oss_fuzz_build_url,
|
| 278 |
+
self.workspace.clusterfuzz_build):
|
| 279 |
+
logging.info('Done downloading latest build.')
|
| 280 |
+
return self.workspace.clusterfuzz_build
|
| 281 |
+
|
| 282 |
+
return None
|
| 283 |
+
|
| 284 |
+
def upload_build(self, commit): # pylint: disable=no-self-use
|
| 285 |
+
"""Noop Implementation of upload_build."""
|
| 286 |
+
logging.info('Not uploading latest build because on OSS-Fuzz.')
|
| 287 |
+
|
| 288 |
+
def upload_corpus(self, target_name, corpus_dir, replace=False): # pylint: disable=no-self-use,unused-argument
|
| 289 |
+
"""Noop Implementation of upload_corpus."""
|
| 290 |
+
logging.info('Not uploading corpus because on OSS-Fuzz.')
|
| 291 |
+
|
| 292 |
+
def upload_crashes(self): # pylint: disable=no-self-use
|
| 293 |
+
"""Noop Implementation of upload_crashes."""
|
| 294 |
+
logging.info('Not uploading crashes because on OSS-Fuzz.')
|
| 295 |
+
|
| 296 |
+
def download_corpus(self, target_name, corpus_dir):
|
| 297 |
+
"""Downloads the latest OSS-Fuzz corpus for the target.
|
| 298 |
+
|
| 299 |
+
Returns:
|
| 300 |
+
The local path to to corpus or None if download failed.
|
| 301 |
+
"""
|
| 302 |
+
_make_empty_dir_if_nonexistent(corpus_dir)
|
| 303 |
+
project_qualified_fuzz_target_name = target_name
|
| 304 |
+
qualified_name_prefix = self.config.oss_fuzz_project_name + '_'
|
| 305 |
+
if not target_name.startswith(qualified_name_prefix):
|
| 306 |
+
project_qualified_fuzz_target_name = qualified_name_prefix + target_name
|
| 307 |
+
|
| 308 |
+
corpus_url = (f'{utils.GCS_BASE_URL}{self.config.oss_fuzz_project_name}'
|
| 309 |
+
'-backup.clusterfuzz-external.appspot.com/corpus/'
|
| 310 |
+
f'libFuzzer/{project_qualified_fuzz_target_name}/'
|
| 311 |
+
f'{self.CORPUS_ZIP_NAME}')
|
| 312 |
+
logging.info('Downloading corpus from OSS-Fuzz: %s', corpus_url)
|
| 313 |
+
|
| 314 |
+
if not http_utils.download_and_unpack_zip(corpus_url, corpus_dir):
|
| 315 |
+
logging.warning('Failed to download corpus for %s.', target_name)
|
| 316 |
+
return corpus_dir
|
| 317 |
+
|
| 318 |
+
def upload_coverage(self):
|
| 319 |
+
"""Noop Implementation of upload_coverage_report."""
|
| 320 |
+
logging.info('Not uploading coverage report because on OSS-Fuzz.')
|
| 321 |
+
|
| 322 |
+
def get_coverage(self, repo_path):
|
| 323 |
+
"""Returns the project coverage object for the project."""
|
| 324 |
+
try:
|
| 325 |
+
return get_coverage.OSSFuzzCoverage(repo_path,
|
| 326 |
+
self.config.oss_fuzz_project_name)
|
| 327 |
+
except get_coverage.CoverageError:
|
| 328 |
+
return None
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
class NoClusterFuzzDeployment(BaseClusterFuzzDeployment):
|
| 332 |
+
"""ClusterFuzzDeployment implementation used when there is no deployment of
|
| 333 |
+
ClusterFuzz to use."""
|
| 334 |
+
|
| 335 |
+
def upload_build(self, commit): # pylint: disable=no-self-use
|
| 336 |
+
"""Noop Implementation of upload_build."""
|
| 337 |
+
logging.info('Not uploading latest build because no ClusterFuzz '
|
| 338 |
+
'deployment.')
|
| 339 |
+
|
| 340 |
+
def upload_corpus(self, target_name, corpus_dir, replace=False): # pylint: disable=no-self-use,unused-argument
|
| 341 |
+
"""Noop Implementation of upload_corpus."""
|
| 342 |
+
logging.info('Not uploading corpus because no ClusterFuzz deployment.')
|
| 343 |
+
|
| 344 |
+
def upload_crashes(self): # pylint: disable=no-self-use
|
| 345 |
+
"""Noop Implementation of upload_crashes."""
|
| 346 |
+
logging.info('Not uploading crashes because no ClusterFuzz deployment.')
|
| 347 |
+
|
| 348 |
+
def download_corpus(self, target_name, corpus_dir):
|
| 349 |
+
"""Noop Implementation of download_corpus."""
|
| 350 |
+
logging.info('Not downloading corpus because no ClusterFuzz deployment.')
|
| 351 |
+
return _make_empty_dir_if_nonexistent(corpus_dir)
|
| 352 |
+
|
| 353 |
+
def download_latest_build(self): # pylint: disable=no-self-use
|
| 354 |
+
"""Noop Implementation of download_latest_build."""
|
| 355 |
+
logging.info(
|
| 356 |
+
'Not downloading latest build because no ClusterFuzz deployment.')
|
| 357 |
+
|
| 358 |
+
def upload_coverage(self):
|
| 359 |
+
"""Noop Implementation of upload_coverage."""
|
| 360 |
+
logging.info(
|
| 361 |
+
'Not uploading coverage report because no ClusterFuzz deployment.')
|
| 362 |
+
|
| 363 |
+
def get_coverage(self, repo_path):
|
| 364 |
+
"""Noop Implementation of get_coverage."""
|
| 365 |
+
logging.info(
|
| 366 |
+
'Not getting project coverage because no ClusterFuzz deployment.')
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
_PLATFORM_CLUSTERFUZZ_DEPLOYMENT_MAPPING = {
|
| 370 |
+
config_utils.BaseConfig.Platform.INTERNAL_GENERIC_CI: OSSFuzz,
|
| 371 |
+
config_utils.BaseConfig.Platform.INTERNAL_GITHUB: OSSFuzz,
|
| 372 |
+
config_utils.BaseConfig.Platform.EXTERNAL_GENERIC_CI: ClusterFuzzLite,
|
| 373 |
+
config_utils.BaseConfig.Platform.EXTERNAL_GITHUB: ClusterFuzzLite,
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def get_clusterfuzz_deployment(config, workspace):
|
| 378 |
+
"""Returns object reprsenting deployment of ClusterFuzz used by |config|."""
|
| 379 |
+
deployment_cls = _PLATFORM_CLUSTERFUZZ_DEPLOYMENT_MAPPING[config.platform]
|
| 380 |
+
if config.no_clusterfuzz_deployment:
|
| 381 |
+
logging.info('Overriding ClusterFuzzDeployment. Using None.')
|
| 382 |
+
deployment_cls = NoClusterFuzzDeployment
|
| 383 |
+
result = deployment_cls(config, workspace)
|
| 384 |
+
logging.info('ClusterFuzzDeployment: %s.', result)
|
| 385 |
+
return result
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/continuous_integration_test.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Tests for continuous_integration_module."""
|
| 15 |
+
import os
|
| 16 |
+
import sys
|
| 17 |
+
import unittest
|
| 18 |
+
from unittest import mock
|
| 19 |
+
|
| 20 |
+
import continuous_integration
|
| 21 |
+
import docker
|
| 22 |
+
|
| 23 |
+
# pylint: disable=wrong-import-position,import-error
|
| 24 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 25 |
+
|
| 26 |
+
import repo_manager
|
| 27 |
+
|
| 28 |
+
# pylint: disable=no-self-use
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class FixGitRepoForDiffTest(unittest.TestCase):
|
| 32 |
+
"""Tests for fix_git_repo_for_diff."""
|
| 33 |
+
|
| 34 |
+
@mock.patch('utils.execute')
|
| 35 |
+
def test_fix_git_repo_for_diff(self, mock_execute):
|
| 36 |
+
"""Tests that fix_git_repo_for_diff works as intended."""
|
| 37 |
+
repo_dir = '/dir'
|
| 38 |
+
repo_manager_obj = repo_manager.RepoManager(repo_dir)
|
| 39 |
+
continuous_integration.fix_git_repo_for_diff(repo_manager_obj)
|
| 40 |
+
expected_command = [
|
| 41 |
+
'git', 'symbolic-ref', 'refs/remotes/origin/HEAD',
|
| 42 |
+
'refs/remotes/origin/master'
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
mock_execute.assert_called_with(expected_command, location=repo_dir)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class GetBuildCommand(unittest.TestCase):
|
| 49 |
+
"""Tests for get_build_command."""
|
| 50 |
+
|
| 51 |
+
def test_build_command(self):
|
| 52 |
+
"""Tests that get_build_command works as intended."""
|
| 53 |
+
self.assertEqual(continuous_integration.get_build_command(), 'compile')
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class GetReplaceRepoAndBuildCommand(unittest.TestCase):
|
| 57 |
+
"""Tests for get_replace_repo_and_build_command."""
|
| 58 |
+
|
| 59 |
+
def test_get_replace_repo_and_build_command(self):
|
| 60 |
+
"""Tests that get_replace_repo_and_build_command works as intended."""
|
| 61 |
+
host_repo_path = '/path/on/host/to/repo'
|
| 62 |
+
image_repo_path = '/src/repo'
|
| 63 |
+
command = continuous_integration.get_replace_repo_and_build_command(
|
| 64 |
+
host_repo_path, image_repo_path)
|
| 65 |
+
expected_command = ('cd / && rm -rf /src/repo/* && '
|
| 66 |
+
'cp -r /path/on/host/to/repo /src && cd - '
|
| 67 |
+
'&& compile')
|
| 68 |
+
self.assertEqual(command, expected_command)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class BuildExternalProjetDockerImage(unittest.TestCase):
|
| 72 |
+
"""Tests for build_external_project_docker_image."""
|
| 73 |
+
|
| 74 |
+
@mock.patch('helper.docker_build')
|
| 75 |
+
def test_build_external_project_docker_image(self, mock_docker_build):
|
| 76 |
+
"""Tests that build_external_project_docker_image works as intended."""
|
| 77 |
+
build_integration_path = '.clusterfuzzlite'
|
| 78 |
+
project_src = '/path/to/project/src'
|
| 79 |
+
continuous_integration.build_external_project_docker_image(
|
| 80 |
+
project_src, build_integration_path)
|
| 81 |
+
|
| 82 |
+
mock_docker_build.assert_called_with([
|
| 83 |
+
'-t', docker.EXTERNAL_PROJECT_IMAGE, '-f',
|
| 84 |
+
os.path.join('.clusterfuzzlite', 'Dockerfile'), project_src
|
| 85 |
+
])
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# TODO(metzman): Write tests for the rest of continuous_integration.py.
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/docker.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Module for dealing with docker."""
|
| 15 |
+
import logging
|
| 16 |
+
import os
|
| 17 |
+
import sys
|
| 18 |
+
import uuid
|
| 19 |
+
|
| 20 |
+
# pylint: disable=wrong-import-position,import-error
|
| 21 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 22 |
+
|
| 23 |
+
import constants
|
| 24 |
+
import utils
|
| 25 |
+
import environment
|
| 26 |
+
|
| 27 |
+
BASE_BUILDER_TAG = 'ghcr.io/aixcc-finals/base-builder'
|
| 28 |
+
PROJECT_TAG_PREFIX = 'gcr.io/oss-fuzz/'
|
| 29 |
+
|
| 30 |
+
# Default fuzz configuration.
|
| 31 |
+
_DEFAULT_DOCKER_RUN_ARGS = [
|
| 32 |
+
'-e', 'FUZZING_ENGINE=' + constants.DEFAULT_ENGINE, '-e', 'CIFUZZ=True'
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
UNIQUE_ID_SUFFIX = '-' + uuid.uuid4().hex
|
| 36 |
+
|
| 37 |
+
# TODO(metzman): Make run_fuzzers able to delete this image.
|
| 38 |
+
EXTERNAL_PROJECT_IMAGE = 'external-cfl-project' + UNIQUE_ID_SUFFIX
|
| 39 |
+
|
| 40 |
+
_DEFAULT_DOCKER_RUN_COMMAND = [
|
| 41 |
+
'docker',
|
| 42 |
+
'run',
|
| 43 |
+
'--rm',
|
| 44 |
+
'--privileged',
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def get_docker_env_vars(env_mapping):
|
| 49 |
+
"""Returns a list of docker arguments that sets each key in |env_mapping| as
|
| 50 |
+
an env var and the value of that key in |env_mapping| as the value."""
|
| 51 |
+
env_var_args = []
|
| 52 |
+
for env_var, env_var_val in env_mapping.items():
|
| 53 |
+
env_var_args.extend(['-e', f'{env_var}={env_var_val}'])
|
| 54 |
+
return env_var_args
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def get_project_image_name(project):
|
| 58 |
+
"""Returns the name of the project builder image for |project_name|."""
|
| 59 |
+
# TODO(jonathanmetzman): We may need unique names to support parallel fuzzing
|
| 60 |
+
# for CIFuzz (like CFL supports). Don't do this for now because no one has
|
| 61 |
+
# asked for it and build_specified_commit would need to be modified to support
|
| 62 |
+
# this.
|
| 63 |
+
if project:
|
| 64 |
+
return PROJECT_TAG_PREFIX + project
|
| 65 |
+
|
| 66 |
+
return EXTERNAL_PROJECT_IMAGE
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def delete_images(images):
|
| 70 |
+
"""Deletes |images|."""
|
| 71 |
+
command = ['docker', 'rmi', '-f'] + images
|
| 72 |
+
utils.execute(command)
|
| 73 |
+
utils.execute(['docker', 'builder', 'prune', '-f'])
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def get_base_docker_run_args(workspace,
|
| 77 |
+
sanitizer=constants.DEFAULT_SANITIZER,
|
| 78 |
+
language=constants.DEFAULT_LANGUAGE,
|
| 79 |
+
architecture=constants.DEFAULT_ARCHITECTURE,
|
| 80 |
+
docker_in_docker=False):
|
| 81 |
+
"""Returns arguments that should be passed to every invocation of 'docker
|
| 82 |
+
run'."""
|
| 83 |
+
docker_args = _DEFAULT_DOCKER_RUN_ARGS.copy()
|
| 84 |
+
env_mapping = {
|
| 85 |
+
'SANITIZER': sanitizer,
|
| 86 |
+
'ARCHITECTURE': architecture,
|
| 87 |
+
'FUZZING_LANGUAGE': language,
|
| 88 |
+
'OUT': workspace.out
|
| 89 |
+
}
|
| 90 |
+
docker_args += get_docker_env_vars(env_mapping)
|
| 91 |
+
docker_container = environment.get('CFL_CONTAINER_ID',
|
| 92 |
+
utils.get_container_name())
|
| 93 |
+
logging.info('Docker container: %s.', docker_container)
|
| 94 |
+
if docker_container and not docker_in_docker:
|
| 95 |
+
# Don't map specific volumes if in a docker container, it breaks when
|
| 96 |
+
# running a sibling container.
|
| 97 |
+
docker_args += ['--volumes-from', docker_container]
|
| 98 |
+
else:
|
| 99 |
+
docker_args += _get_args_mapping_host_path_to_container(workspace.workspace)
|
| 100 |
+
return docker_args, docker_container
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def get_base_docker_run_command(workspace,
|
| 104 |
+
sanitizer=constants.DEFAULT_SANITIZER,
|
| 105 |
+
language=constants.DEFAULT_LANGUAGE,
|
| 106 |
+
architecture=constants.DEFAULT_ARCHITECTURE,
|
| 107 |
+
docker_in_docker=False):
|
| 108 |
+
"""Returns part of the command that should be used everytime 'docker run' is
|
| 109 |
+
invoked."""
|
| 110 |
+
docker_args, docker_container = get_base_docker_run_args(
|
| 111 |
+
workspace,
|
| 112 |
+
sanitizer,
|
| 113 |
+
language,
|
| 114 |
+
architecture,
|
| 115 |
+
docker_in_docker=docker_in_docker)
|
| 116 |
+
command = _DEFAULT_DOCKER_RUN_COMMAND.copy() + docker_args
|
| 117 |
+
return command, docker_container
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def _get_args_mapping_host_path_to_container(host_path, container_path=None):
|
| 121 |
+
"""Get arguments to docker run that will map |host_path| a path on the host to
|
| 122 |
+
a path in the container. If |container_path| is specified, that path is mapped
|
| 123 |
+
to. If not, then |host_path| is mapped to itself in the container."""
|
| 124 |
+
# WARNING: Do not use this function when running in production (and
|
| 125 |
+
# --volumes-from) is used for mapping volumes. It will break production.
|
| 126 |
+
container_path = host_path if container_path is None else container_path
|
| 127 |
+
return ['-v', f'{host_path}:{container_path}']
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/logs.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Log helpers."""
|
| 15 |
+
|
| 16 |
+
import logging
|
| 17 |
+
import os
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def init():
|
| 21 |
+
"""Initialize logging."""
|
| 22 |
+
log_level = logging.DEBUG if os.getenv('CIFUZZ_DEBUG') else logging.INFO
|
| 23 |
+
logging.basicConfig(
|
| 24 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 25 |
+
level=log_level)
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
clusterfuzz==2.5.9
|
| 2 |
+
requests==2.28.0
|
| 3 |
+
protobuf==3.20.2
|
| 4 |
+
gsutil==5.20
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/run_cifuzz.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Script for running CIFuzz end-to-end. This is meant to work outside any
|
| 15 |
+
docker image. This cannot depend on any CIFuzz code or third party packages."""
|
| 16 |
+
import os
|
| 17 |
+
import subprocess
|
| 18 |
+
import sys
|
| 19 |
+
import tempfile
|
| 20 |
+
import logging
|
| 21 |
+
|
| 22 |
+
INFRA_DIR = os.path.dirname(os.path.dirname(__file__))
|
| 23 |
+
DEFAULT_ENVS = [('DRY_RUN', '0'), ('SANITIZER', 'address')]
|
| 24 |
+
BASE_CIFUZZ_DOCKER_TAG = 'ghcr.io/aixcc-finals'
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def set_default_env_var_if_unset(env_var, default_value):
|
| 28 |
+
"""Sets the value of |env_var| in the environment to |default_value| if it was
|
| 29 |
+
not already set."""
|
| 30 |
+
if env_var not in os.environ:
|
| 31 |
+
os.environ[env_var] = default_value
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def docker_run(name, workspace, project_src_path):
|
| 35 |
+
"""Runs a CIFuzz docker container with |name|."""
|
| 36 |
+
command = [
|
| 37 |
+
'docker', 'run', '--name', name, '--rm', '-e', 'PROJECT_SRC_PATH', '-e',
|
| 38 |
+
'OSS_FUZZ_PROJECT_NAME', '-e', 'WORKSPACE', '-e', 'REPOSITORY', '-e',
|
| 39 |
+
'DRY_RUN', '-e', 'CI', '-e', 'SANITIZER', '-e', 'GIT_SHA', '-e',
|
| 40 |
+
'FILESTORE', '-e', 'NO_CLUSTERFUZZ_DEPLOYMENT'
|
| 41 |
+
]
|
| 42 |
+
if project_src_path:
|
| 43 |
+
command += ['-v', f'{project_src_path}:{project_src_path}']
|
| 44 |
+
command += [
|
| 45 |
+
'-v', '/var/run/docker.sock:/var/run/docker.sock', '-v',
|
| 46 |
+
f'{workspace}:{workspace}', f'{BASE_CIFUZZ_DOCKER_TAG}/{name}'
|
| 47 |
+
]
|
| 48 |
+
print('Running docker command:', command)
|
| 49 |
+
subprocess.run(command, check=True)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def docker_build(image):
|
| 53 |
+
"""Builds the CIFuzz |image|. Only suitable for building CIFuzz images."""
|
| 54 |
+
command = [
|
| 55 |
+
'docker', 'build', '-t', f'{BASE_CIFUZZ_DOCKER_TAG}/{image}', '--file',
|
| 56 |
+
f'{image}.Dockerfile', '.'
|
| 57 |
+
]
|
| 58 |
+
subprocess.run(command, check=True, cwd=INFRA_DIR)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def main():
|
| 62 |
+
"""Builds and runs fuzzers using CIFuzz."""
|
| 63 |
+
for env_var, default_value in DEFAULT_ENVS:
|
| 64 |
+
set_default_env_var_if_unset(env_var, default_value)
|
| 65 |
+
|
| 66 |
+
repository = os.getenv('REPOSITORY')
|
| 67 |
+
assert repository
|
| 68 |
+
|
| 69 |
+
project_src_path = os.getenv('PROJECT_SRC_PATH')
|
| 70 |
+
|
| 71 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 72 |
+
if 'WORKSPACE' not in os.environ:
|
| 73 |
+
os.environ['WORKSPACE'] = temp_dir
|
| 74 |
+
|
| 75 |
+
workspace = os.environ['WORKSPACE']
|
| 76 |
+
|
| 77 |
+
docker_build('build_fuzzers')
|
| 78 |
+
docker_run('build_fuzzers', workspace, project_src_path)
|
| 79 |
+
docker_build('run_fuzzers')
|
| 80 |
+
try:
|
| 81 |
+
docker_run('run_fuzzers', workspace, project_src_path)
|
| 82 |
+
except subprocess.CalledProcessError:
|
| 83 |
+
logging.error('run_fuzzers failed.')
|
| 84 |
+
return 1
|
| 85 |
+
return 0
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
if __name__ == '__main__':
|
| 89 |
+
sys.exit(main())
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/run_fuzzers_entrypoint.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""Runs a specific OSS-Fuzz project's fuzzers for CI tools."""
|
| 15 |
+
import logging
|
| 16 |
+
import sys
|
| 17 |
+
|
| 18 |
+
import config_utils
|
| 19 |
+
import docker
|
| 20 |
+
import logs
|
| 21 |
+
import run_fuzzers
|
| 22 |
+
|
| 23 |
+
# pylint: disable=c-extension-no-member
|
| 24 |
+
# pylint gets confused because of the relative import of cifuzz.
|
| 25 |
+
|
| 26 |
+
logs.init()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def delete_unneeded_docker_images(config):
|
| 30 |
+
"""Deletes unneeded docker images if running in an environment with low
|
| 31 |
+
disk space."""
|
| 32 |
+
if not config.low_disk_space:
|
| 33 |
+
return
|
| 34 |
+
logging.info('Deleting builder docker images to save disk space.')
|
| 35 |
+
project_image = docker.get_project_image_name(config.oss_fuzz_project_name)
|
| 36 |
+
images = [
|
| 37 |
+
project_image,
|
| 38 |
+
docker.BASE_BUILDER_TAG,
|
| 39 |
+
docker.BASE_BUILDER_TAG + '-go',
|
| 40 |
+
docker.BASE_BUILDER_TAG + '-javascript',
|
| 41 |
+
docker.BASE_BUILDER_TAG + '-jvm',
|
| 42 |
+
docker.BASE_BUILDER_TAG + '-python',
|
| 43 |
+
docker.BASE_BUILDER_TAG + '-rust',
|
| 44 |
+
docker.BASE_BUILDER_TAG + '-ruby',
|
| 45 |
+
docker.BASE_BUILDER_TAG + '-swift',
|
| 46 |
+
]
|
| 47 |
+
docker.delete_images(images)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def run_fuzzers_entrypoint():
|
| 51 |
+
"""This is the entrypoint for the run_fuzzers github action.
|
| 52 |
+
This action can be added to any OSS-Fuzz project's workflow that uses
|
| 53 |
+
Github."""
|
| 54 |
+
config = config_utils.RunFuzzersConfig()
|
| 55 |
+
# The default return code when an error occurs.
|
| 56 |
+
returncode = 1
|
| 57 |
+
if config.dry_run:
|
| 58 |
+
# Sets the default return code on error to success.
|
| 59 |
+
returncode = 0
|
| 60 |
+
|
| 61 |
+
delete_unneeded_docker_images(config)
|
| 62 |
+
# Run the specified project's fuzzers from the build.
|
| 63 |
+
result = run_fuzzers.run_fuzzers(config)
|
| 64 |
+
if result == run_fuzzers.RunFuzzersResult.ERROR:
|
| 65 |
+
logging.error('Error occurred while running in workspace %s.',
|
| 66 |
+
config.workspace)
|
| 67 |
+
return returncode
|
| 68 |
+
if result == run_fuzzers.RunFuzzersResult.BUG_FOUND:
|
| 69 |
+
logging.info('Bug found.')
|
| 70 |
+
if not config.dry_run:
|
| 71 |
+
# Return 2 when a bug was found by a fuzzer causing the CI to fail.
|
| 72 |
+
return 2
|
| 73 |
+
return 0
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def main():
|
| 77 |
+
"""Runs project's fuzzers for CI tools.
|
| 78 |
+
This is the entrypoint for the run_fuzzers github action.
|
| 79 |
+
|
| 80 |
+
NOTE: libFuzzer binaries must be located in the $WORKSPACE/build-out
|
| 81 |
+
directory in order for this action to be used. This action will only fuzz the
|
| 82 |
+
binaries that are located in that directory. It is recommended that you add
|
| 83 |
+
the build_fuzzers action preceding this one.
|
| 84 |
+
|
| 85 |
+
NOTE: Any crash report will be in the filepath:
|
| 86 |
+
${GITHUB_WORKSPACE}/out/testcase
|
| 87 |
+
This can be used in parallel with the upload-artifact action to surface the
|
| 88 |
+
logs.
|
| 89 |
+
|
| 90 |
+
Returns:
|
| 91 |
+
0 on success or nonzero on failure.
|
| 92 |
+
"""
|
| 93 |
+
return run_fuzzers_entrypoint()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if __name__ == '__main__':
|
| 97 |
+
sys.exit(main())
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/cifuzz/sarif_utils.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"""Module for outputting SARIF data."""
|
| 15 |
+
import copy
|
| 16 |
+
import json
|
| 17 |
+
import logging
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
from clusterfuzz import stacktraces
|
| 21 |
+
|
| 22 |
+
SARIF_RULES = [
|
| 23 |
+
{
|
| 24 |
+
'id': 'no-crashes',
|
| 25 |
+
'shortDescription': {
|
| 26 |
+
'text': 'Don\'t crash'
|
| 27 |
+
},
|
| 28 |
+
'helpUri': 'https://cwe.mitre.org/data/definitions/416.html',
|
| 29 |
+
'properties': {
|
| 30 |
+
'category': 'Crashes'
|
| 31 |
+
}
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
'id': 'heap-use-after-free',
|
| 35 |
+
'shortDescription': {
|
| 36 |
+
'text': 'Use of a heap-object after it has been freed.'
|
| 37 |
+
},
|
| 38 |
+
'helpUri': 'https://cwe.mitre.org/data/definitions/416.html',
|
| 39 |
+
'properties': {
|
| 40 |
+
'category': 'Crashes'
|
| 41 |
+
}
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
'id': 'heap-buffer-overflow',
|
| 45 |
+
'shortDescription': {
|
| 46 |
+
'text': 'A read or write past the end of a heap buffer.'
|
| 47 |
+
},
|
| 48 |
+
'helpUri': 'https://cwe.mitre.org/data/definitions/122.html',
|
| 49 |
+
'properties': {
|
| 50 |
+
'category': 'Crashes'
|
| 51 |
+
}
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
'id': 'stack-buffer-overflow',
|
| 55 |
+
'shortDescription': {
|
| 56 |
+
'text': 'A read or write past the end of a stack buffer.'
|
| 57 |
+
},
|
| 58 |
+
'helpUri': 'https://cwe.mitre.org/data/definitions/121.html',
|
| 59 |
+
'properties': {
|
| 60 |
+
'category': 'Crashes'
|
| 61 |
+
}
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
'id': 'global-buffer-overflow',
|
| 65 |
+
'shortDescription': {
|
| 66 |
+
'text': 'A read or write past the end of a global buffer.'
|
| 67 |
+
},
|
| 68 |
+
'helpUri': 'https://cwe.mitre.org/data/definitions/121.html',
|
| 69 |
+
'properties': {
|
| 70 |
+
'category': 'Crashes'
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
'id': 'stack-use-after-return',
|
| 75 |
+
'shortDescription': {
|
| 76 |
+
'text':
|
| 77 |
+
'A stack-based variable has been used after the function returned.'
|
| 78 |
+
},
|
| 79 |
+
'helpUri': 'https://cwe.mitre.org/data/definitions/562.html',
|
| 80 |
+
'properties': {
|
| 81 |
+
'category': 'Crashes'
|
| 82 |
+
}
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
'id': 'stack-use-after-scope',
|
| 86 |
+
'shortDescription': {
|
| 87 |
+
'text':
|
| 88 |
+
'A stack-based variable has been used outside of the scope in which it exists.'
|
| 89 |
+
},
|
| 90 |
+
'helpUri': 'https://cwe.mitre.org/data/definitions/562.html',
|
| 91 |
+
'properties': {
|
| 92 |
+
'category': 'Crashes'
|
| 93 |
+
}
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
'id': 'initialization-order-fiasco',
|
| 97 |
+
'shortDescription': {
|
| 98 |
+
'text': 'Problem with order of initialization of global objects.'
|
| 99 |
+
},
|
| 100 |
+
'helpUri': 'https://isocpp.org/wiki/faq/ctors#static-init-order',
|
| 101 |
+
'properties': {
|
| 102 |
+
'category': 'Crashes'
|
| 103 |
+
}
|
| 104 |
+
},
|
| 105 |
+
{
|
| 106 |
+
'id':
|
| 107 |
+
'direct-leak',
|
| 108 |
+
'shortDescription': {
|
| 109 |
+
'text': 'Memory is leaked.'
|
| 110 |
+
},
|
| 111 |
+
'helpUri':
|
| 112 |
+
'https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer',
|
| 113 |
+
'properties': {
|
| 114 |
+
'category': 'Crashes'
|
| 115 |
+
}
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
'id':
|
| 119 |
+
'indirect-leak',
|
| 120 |
+
'shortDescription': {
|
| 121 |
+
'text': 'Memory is leaked.'
|
| 122 |
+
},
|
| 123 |
+
'helpUri':
|
| 124 |
+
'https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer',
|
| 125 |
+
'properties': {
|
| 126 |
+
'category': 'Crashes'
|
| 127 |
+
}
|
| 128 |
+
},
|
| 129 |
+
]
|
| 130 |
+
SARIF_DATA = {
|
| 131 |
+
'version':
|
| 132 |
+
'2.1.0',
|
| 133 |
+
'$schema':
|
| 134 |
+
'http://json.schemastore.org/sarif-2.1.0-rtm.4',
|
| 135 |
+
'runs': [{
|
| 136 |
+
'tool': {
|
| 137 |
+
'driver': {
|
| 138 |
+
'name': 'ClusterFuzzLite/CIFuzz',
|
| 139 |
+
'informationUri': 'https://google.github.io/clusterfuzzlite/',
|
| 140 |
+
'rules': SARIF_RULES,
|
| 141 |
+
}
|
| 142 |
+
},
|
| 143 |
+
'results': []
|
| 144 |
+
}]
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
SRC_ROOT = '/src/'
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def redact_src_path(src_path):
|
| 151 |
+
"""Redact the src path so that it can be reported to users."""
|
| 152 |
+
src_path = os.path.normpath(src_path)
|
| 153 |
+
if src_path.startswith(SRC_ROOT):
|
| 154 |
+
src_path = src_path[len(SRC_ROOT):]
|
| 155 |
+
|
| 156 |
+
src_path = os.sep.join(src_path.split(os.sep)[1:])
|
| 157 |
+
return src_path
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def get_error_frame(crash_info):
|
| 161 |
+
"""Returns the stackframe where the error occurred."""
|
| 162 |
+
if not crash_info.crash_state:
|
| 163 |
+
return None
|
| 164 |
+
state = crash_info.crash_state.split('\n')[0]
|
| 165 |
+
logging.info('state: %s frames %s, %s', state, crash_info.frames,
|
| 166 |
+
[f.function_name for f in crash_info.frames[0]])
|
| 167 |
+
|
| 168 |
+
for crash_frames in crash_info.frames:
|
| 169 |
+
for frame in crash_frames:
|
| 170 |
+
# TODO(metzman): Do something less fragile here.
|
| 171 |
+
if frame.function_name is None:
|
| 172 |
+
continue
|
| 173 |
+
if state in frame.function_name:
|
| 174 |
+
return frame
|
| 175 |
+
return None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def get_error_source_info(crash_info):
|
| 179 |
+
"""Returns the filename and the line where the bug occurred."""
|
| 180 |
+
frame = get_error_frame(crash_info)
|
| 181 |
+
if not frame:
|
| 182 |
+
return (None, 1)
|
| 183 |
+
try:
|
| 184 |
+
return redact_src_path(frame.filename), int(frame.fileline or 1)
|
| 185 |
+
except TypeError:
|
| 186 |
+
return (None, 1)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def get_rule_index(crash_type):
|
| 190 |
+
"""Returns the rule index describe the rule that |crash_type| ran afoul of."""
|
| 191 |
+
# Don't include "READ" or "WRITE" or number of bytes.
|
| 192 |
+
crash_type = crash_type.replace('\n', ' ').split(' ')[0].lower()
|
| 193 |
+
logging.info('crash_type: %s.', crash_type)
|
| 194 |
+
for idx, rule in enumerate(SARIF_RULES):
|
| 195 |
+
if rule['id'] == crash_type:
|
| 196 |
+
logging.info('Rule index: %d.', idx)
|
| 197 |
+
return idx
|
| 198 |
+
|
| 199 |
+
return get_rule_index('no-crashes')
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def get_sarif_data(stacktrace, target_path):
|
| 203 |
+
"""Returns a description of the crash in SARIF."""
|
| 204 |
+
data = copy.deepcopy(SARIF_DATA)
|
| 205 |
+
if stacktrace is None:
|
| 206 |
+
return data
|
| 207 |
+
|
| 208 |
+
fuzz_target = os.path.basename(target_path)
|
| 209 |
+
stack_parser = stacktraces.StackParser(fuzz_target=fuzz_target,
|
| 210 |
+
symbolized=True,
|
| 211 |
+
detect_ooms_and_hangs=True,
|
| 212 |
+
include_ubsan=True)
|
| 213 |
+
crash_info = stack_parser.parse(stacktrace)
|
| 214 |
+
error_source_info = get_error_source_info(crash_info)
|
| 215 |
+
rule_idx = get_rule_index(crash_info.crash_type)
|
| 216 |
+
rule_id = SARIF_RULES[rule_idx]['id']
|
| 217 |
+
uri = error_source_info[0]
|
| 218 |
+
|
| 219 |
+
result = {
|
| 220 |
+
'level': 'error',
|
| 221 |
+
'message': {
|
| 222 |
+
'text': crash_info.crash_type
|
| 223 |
+
},
|
| 224 |
+
'locations': [{
|
| 225 |
+
'physicalLocation': {
|
| 226 |
+
'artifactLocation': {
|
| 227 |
+
'uri': uri,
|
| 228 |
+
'index': 0
|
| 229 |
+
},
|
| 230 |
+
'region': {
|
| 231 |
+
'startLine': error_source_info[1],
|
| 232 |
+
# We don't have this granualarity fuzzing.
|
| 233 |
+
'startColumn': 1,
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
}],
|
| 237 |
+
'ruleId': rule_id,
|
| 238 |
+
'ruleIndex': rule_idx
|
| 239 |
+
}
|
| 240 |
+
if uri:
|
| 241 |
+
data['runs'][0]['results'].append(result)
|
| 242 |
+
return data
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def write_stacktrace_to_sarif(stacktrace, target_path, workspace):
|
| 246 |
+
"""Writes a description of the crash in stacktrace to a SARIF file."""
|
| 247 |
+
data = get_sarif_data(stacktrace, target_path)
|
| 248 |
+
if not os.path.exists(workspace.sarif):
|
| 249 |
+
os.makedirs(workspace.sarif)
|
| 250 |
+
with open(os.path.join(workspace.sarif, 'results.sarif'), 'w') as file_handle:
|
| 251 |
+
file_handle.write(json.dumps(data))
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/tools/hold_back_images.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
"""Script for pinning builder images for projects that break on upgrades. Works
|
| 18 |
+
with projects that use language builders."""
|
| 19 |
+
import argparse
|
| 20 |
+
import logging
|
| 21 |
+
import os
|
| 22 |
+
import re
|
| 23 |
+
import sys
|
| 24 |
+
import subprocess
|
| 25 |
+
|
| 26 |
+
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
| 27 |
+
PROJECTS_DIR = os.path.join(ROOT_DIR, 'projects')
|
| 28 |
+
|
| 29 |
+
IMAGE_DIGEST_REGEX = re.compile(r'\[(.+)\]\n')
|
| 30 |
+
FROM_LINE_REGEX = re.compile(
|
| 31 |
+
r'FROM (ghcr.io\/aixcc-finals\/base-builder[\-a-z0-9]*)(\@?.*)')
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def get_latest_docker_image_digest(image):
|
| 35 |
+
"""Returns a pinnable version of the latest |image|. This version will have a
|
| 36 |
+
SHA."""
|
| 37 |
+
subprocess.run(['docker', 'pull', image], check=True)
|
| 38 |
+
subprocess.run(['docker', 'pull', image], stdout=subprocess.PIPE, check=True)
|
| 39 |
+
|
| 40 |
+
command = [
|
| 41 |
+
'docker', 'image', 'inspect', '--format', '{{.RepoDigests}}', image
|
| 42 |
+
]
|
| 43 |
+
output = subprocess.run(command, check=True,
|
| 44 |
+
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
| 45 |
+
return IMAGE_DIGEST_REGEX.match(output).groups(1)[0]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def get_args():
|
| 49 |
+
"""Returns parsed arguments."""
|
| 50 |
+
parser = argparse.ArgumentParser(sys.argv[0],
|
| 51 |
+
description='Hold back builder images.')
|
| 52 |
+
parser.add_argument('projects', help='Projects.', nargs='+')
|
| 53 |
+
|
| 54 |
+
parser.add_argument('--hold-image-digest',
|
| 55 |
+
required=False,
|
| 56 |
+
nargs='?',
|
| 57 |
+
default=None,
|
| 58 |
+
help='Image to hold on to.')
|
| 59 |
+
|
| 60 |
+
parser.add_argument('--update-held',
|
| 61 |
+
action='store_true',
|
| 62 |
+
default=False,
|
| 63 |
+
help='Update held images.')
|
| 64 |
+
|
| 65 |
+
parser.add_argument('--issue-number',
|
| 66 |
+
required=False,
|
| 67 |
+
nargs='?',
|
| 68 |
+
default=None,
|
| 69 |
+
help='Issue to reference.')
|
| 70 |
+
|
| 71 |
+
args = parser.parse_args()
|
| 72 |
+
return args
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def get_hold_image_digest(line, hold_image_digest, update_held):
|
| 76 |
+
"""Returns the image digest for the |line| we want to pin. If the image is
|
| 77 |
+
already pinned then it is only updated if |update_held. If |hold_image_digest
|
| 78 |
+
is specified then it is returned, otherwise the latest pinnable version is
|
| 79 |
+
returned."""
|
| 80 |
+
matches = FROM_LINE_REGEX.match(line).groups()
|
| 81 |
+
if matches[1] and not update_held:
|
| 82 |
+
return None, False
|
| 83 |
+
initial_image = matches[0]
|
| 84 |
+
if hold_image_digest:
|
| 85 |
+
return hold_image_digest, True
|
| 86 |
+
return get_latest_docker_image_digest(initial_image), True
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def hold_image(project, hold_image_digest, update_held, issue_number):
|
| 90 |
+
"""Rewrites the Dockerfile of |project| to pin the base-builder image on
|
| 91 |
+
upgrade."""
|
| 92 |
+
dockerfile_path = os.path.join(PROJECTS_DIR, project, 'Dockerfile')
|
| 93 |
+
with open(dockerfile_path, 'r') as dockerfile_handle:
|
| 94 |
+
dockerfile = dockerfile_handle.readlines()
|
| 95 |
+
for idx, line in enumerate(dockerfile[:]):
|
| 96 |
+
if not line.startswith('FROM ghcr.io/aixcc-finals/base-builder'):
|
| 97 |
+
continue
|
| 98 |
+
|
| 99 |
+
hold_image_digest, should_hold = get_hold_image_digest(
|
| 100 |
+
line.strip(), hold_image_digest, update_held)
|
| 101 |
+
if not should_hold:
|
| 102 |
+
logging.error('Not holding back %s.', project)
|
| 103 |
+
break
|
| 104 |
+
dockerfile[idx] = f'FROM {hold_image_digest}\n'
|
| 105 |
+
if issue_number:
|
| 106 |
+
comment = ('# Held back because of github.com/google/oss-fuzz/pull/'
|
| 107 |
+
f'{issue_number}\n# Please fix failure and upgrade.\n')
|
| 108 |
+
dockerfile.insert(idx, comment)
|
| 109 |
+
break
|
| 110 |
+
else:
|
| 111 |
+
# This path is taken when we don't break out of the loop.
|
| 112 |
+
assert None, f'Could not find FROM line in {project}'
|
| 113 |
+
dockerfile = ''.join(dockerfile)
|
| 114 |
+
with open(dockerfile_path, 'w') as dockerfile_handle:
|
| 115 |
+
dockerfile_handle.write(dockerfile)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def main():
|
| 119 |
+
"""Script for pinning builder images for projects that break on upgrades."""
|
| 120 |
+
args = get_args()
|
| 121 |
+
for project in args.projects:
|
| 122 |
+
hold_image(project, args.hold_image_digest, args.update_held,
|
| 123 |
+
args.issue_number)
|
| 124 |
+
return 0
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if __name__ == '__main__':
|
| 128 |
+
sys.exit(main())
|
local-test-tika-full-01-vuln_7/fuzz-tooling/infra/uploader/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ubuntu:16.04
|
| 2 |
+
|
| 3 |
+
RUN apt-get update && apt-get upgrade -y
|
| 4 |
+
RUN apt-get install -y curl
|
| 5 |
+
|
| 6 |
+
ENTRYPOINT ["curl", "--retry", "5", "-X", "PUT", "-T"]
|
| 7 |
+
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
build/
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright {yyyy} {name of copyright owner}
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspace.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {println} from '../logger';
|
| 19 |
+
import {commandHistory} from '../commandUtils';
|
| 20 |
+
import {
|
| 21 |
+
hasOssFuzzInWorkspace,
|
| 22 |
+
getOssFuzzWorkspaceProjectName,
|
| 23 |
+
setStatusText,
|
| 24 |
+
} from '../utils';
|
| 25 |
+
import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 26 |
+
|
| 27 |
+
export async function cmdInputCollectorBuildFuzzersFromWorkspace() {
|
| 28 |
+
let ossFuzzProjectName = '';
|
| 29 |
+
// First determine if we have a name in the workspace
|
| 30 |
+
if (await hasOssFuzzInWorkspace()) {
|
| 31 |
+
/**
|
| 32 |
+
* The fuzzers are in the workspace, as opposed to e.g. the oss-fuzz dirctory.
|
| 33 |
+
*/
|
| 34 |
+
ossFuzzProjectName = await getOssFuzzWorkspaceProjectName();
|
| 35 |
+
} else {
|
| 36 |
+
// If we did not have that, ask the user.
|
| 37 |
+
|
| 38 |
+
const ossFuzzProjectNameInput = await vscode.window.showInputBox({
|
| 39 |
+
value: '',
|
| 40 |
+
placeHolder: 'The OSS-Fuzz project name',
|
| 41 |
+
});
|
| 42 |
+
if (!ossFuzzProjectNameInput) {
|
| 43 |
+
println('Did not get a ossFuzzTargetProject');
|
| 44 |
+
return false;
|
| 45 |
+
}
|
| 46 |
+
ossFuzzProjectName = ossFuzzProjectNameInput.toString();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Create an history object
|
| 50 |
+
const args = new Object({
|
| 51 |
+
projectName: ossFuzzProjectName,
|
| 52 |
+
sanitizer: '',
|
| 53 |
+
toClean: false,
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
const commandObject = new Object({
|
| 57 |
+
commandType: 'oss-fuzz.WSBuildFuzzers',
|
| 58 |
+
Arguments: args,
|
| 59 |
+
dispatcherFunc: cmdDispatchBuildFuzzersFromWorkspace,
|
| 60 |
+
});
|
| 61 |
+
console.log('L1: ' + commandHistory.length);
|
| 62 |
+
commandHistory.push(commandObject);
|
| 63 |
+
|
| 64 |
+
await cmdDispatchBuildFuzzersFromWorkspace(args);
|
| 65 |
+
return true;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
async function cmdDispatchBuildFuzzersFromWorkspace(args: any) {
|
| 69 |
+
await setStatusText('Building fuzzers: starting');
|
| 70 |
+
const res = await buildFuzzersFromWorkspace(
|
| 71 |
+
args.projectName,
|
| 72 |
+
args.sanitizer,
|
| 73 |
+
args.toClean
|
| 74 |
+
);
|
| 75 |
+
if (res) {
|
| 76 |
+
await setStatusText('Building fuzzers: finished');
|
| 77 |
+
} else {
|
| 78 |
+
await setStatusText('Building fuzzers: failed');
|
| 79 |
+
}
|
| 80 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdBuildFuzzerFromWorkspaceCFLite.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
| 2 |
+
// Copyright 2023 Google LLC
|
| 3 |
+
//
|
| 4 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
// you may not use this file except in compliance with the License.
|
| 6 |
+
// You may obtain a copy of the License at
|
| 7 |
+
//
|
| 8 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
//
|
| 10 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
// See the License for the specific language governing permissions and
|
| 14 |
+
// limitations under the License.
|
| 15 |
+
//
|
| 16 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 17 |
+
|
| 18 |
+
import {commandHistory} from '../commandUtils';
|
| 19 |
+
import {setStatusText} from '../utils';
|
| 20 |
+
import {buildFuzzersFromWorkspaceClusterfuzzLite} from '../ossfuzzWrappers';
|
| 21 |
+
|
| 22 |
+
export async function cmdInputCollectorBuildFuzzersFromWorkspaceCFLite() {
|
| 23 |
+
// Create an history object
|
| 24 |
+
const args = new Object({
|
| 25 |
+
toClean: false,
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
const commandObject = new Object({
|
| 29 |
+
commandType: 'oss-fuzz.WSBuildFuzzers',
|
| 30 |
+
Arguments: args,
|
| 31 |
+
dispatcherFunc: cmdDispatchbuildFuzzersFromWorkspaceClusterfuzzLite,
|
| 32 |
+
});
|
| 33 |
+
console.log('L1: ' + commandHistory.length);
|
| 34 |
+
commandHistory.push(commandObject);
|
| 35 |
+
|
| 36 |
+
await cmdDispatchbuildFuzzersFromWorkspaceClusterfuzzLite(args);
|
| 37 |
+
return true;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 41 |
+
async function cmdDispatchbuildFuzzersFromWorkspaceClusterfuzzLite(_args: any) {
|
| 42 |
+
await setStatusText('[CFLite] Building fuzzers: starting');
|
| 43 |
+
const res = await buildFuzzersFromWorkspaceClusterfuzzLite();
|
| 44 |
+
if (res) {
|
| 45 |
+
await setStatusText('[CFLite] Building fuzzers: finished');
|
| 46 |
+
} else {
|
| 47 |
+
await setStatusText('[CFLite] Building fuzzers: failed');
|
| 48 |
+
}
|
| 49 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdCreateOSSFuzzSetup.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import {setupProjectInitialFiles} from '../projectIntegrationHelper';
|
| 18 |
+
import {setStatusText} from '../utils';
|
| 19 |
+
|
| 20 |
+
export async function createOssFuzzSetup() {
|
| 21 |
+
await setStatusText('Creating OSS-Fuzz setup: starting');
|
| 22 |
+
const res = await setupProjectInitialFiles(false);
|
| 23 |
+
if (res) {
|
| 24 |
+
await setStatusText('Creating OSS-Fuzz setup: finished');
|
| 25 |
+
} else {
|
| 26 |
+
await setStatusText('Creating OSS-Fuzz setup: failed');
|
| 27 |
+
}
|
| 28 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdDispatcherGenerateClusterfuzzLite.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Command for generating template fuzzers. This is a short-cut for rapid
|
| 19 |
+
* prototyping as well as an archive for inspiration.
|
| 20 |
+
*/
|
| 21 |
+
import * as vscode from 'vscode';
|
| 22 |
+
import {setStatusText} from '../utils';
|
| 23 |
+
|
| 24 |
+
import {setupProjectInitialFiles} from '../projectIntegrationHelper';
|
| 25 |
+
|
| 26 |
+
export async function cmdDispatcherGenerateClusterfuzzLite(
|
| 27 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 28 |
+
_context: vscode.ExtensionContext
|
| 29 |
+
) {
|
| 30 |
+
await setStatusText('Creating OSS-Fuzz setup: starting');
|
| 31 |
+
const res = await setupProjectInitialFiles(true);
|
| 32 |
+
if (res) {
|
| 33 |
+
await setStatusText('Creating OSS-Fuzz setup: finished');
|
| 34 |
+
} else {
|
| 35 |
+
await setStatusText('Creating OSS-Fuzz setup: failed');
|
| 36 |
+
}
|
| 37 |
+
return;
|
| 38 |
+
}
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdEndToEndCoverage.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
const fs = require('fs');
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {commandHistory} from '../commandUtils';
|
| 21 |
+
import {buildFuzzersFromWorkspace, runFuzzerHandler} from '../ossfuzzWrappers';
|
| 22 |
+
import {listFuzzersForProject, systemSync, setStatusText} from '../utils';
|
| 23 |
+
import {
|
| 24 |
+
compareLocalToRemoteCoverage,
|
| 25 |
+
loadCoverageIntoWorkspace,
|
| 26 |
+
} from '../coverageHelper';
|
| 27 |
+
import {extensionConfig} from '../config';
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Performs the activities:
|
| 31 |
+
* 1) Build a project using address sanitizer
|
| 32 |
+
* 2) Run each fuzzer of the project, saving corpus
|
| 33 |
+
* 3) Build project using coverage sanitizer
|
| 34 |
+
* 4) Collect coverage
|
| 35 |
+
* @param context
|
| 36 |
+
* @returns
|
| 37 |
+
*/
|
| 38 |
+
export async function runEndToEndAndGetCoverage(
|
| 39 |
+
context: vscode.ExtensionContext
|
| 40 |
+
) {
|
| 41 |
+
println('Getting code coverage');
|
| 42 |
+
await setStatusText('end-to-end coverage: getting input');
|
| 43 |
+
const ossFuzzProjectNameInput = await vscode.window.showInputBox({
|
| 44 |
+
value: '',
|
| 45 |
+
placeHolder: 'The OSS-Fuzz project name',
|
| 46 |
+
});
|
| 47 |
+
if (!ossFuzzProjectNameInput) {
|
| 48 |
+
println('Did not get a ossFuzzTargetProject');
|
| 49 |
+
return;
|
| 50 |
+
}
|
| 51 |
+
const secondsToRunEachFuzzer = await vscode.window.showInputBox({
|
| 52 |
+
value: '',
|
| 53 |
+
placeHolder: 'Seconds to run each fuzzer',
|
| 54 |
+
});
|
| 55 |
+
if (!secondsToRunEachFuzzer) {
|
| 56 |
+
println('Did not get number of seconds to run each fuzzer');
|
| 57 |
+
return;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// Create an history object
|
| 61 |
+
const args = new Object({
|
| 62 |
+
projectName: ossFuzzProjectNameInput.toString(),
|
| 63 |
+
secondsToRun: secondsToRunEachFuzzer.toString(),
|
| 64 |
+
vsContext: context,
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
const commandObject = new Object({
|
| 68 |
+
commandType: 'oss-fuzz.cmdDispatchEndToEndRun',
|
| 69 |
+
Arguments: args,
|
| 70 |
+
dispatcherFunc: cmdDispatchEndToEndRun,
|
| 71 |
+
});
|
| 72 |
+
console.log('L1: ' + commandHistory.length);
|
| 73 |
+
commandHistory.push(commandObject);
|
| 74 |
+
|
| 75 |
+
await cmdDispatchEndToEndRun(args);
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
async function cmdDispatchEndToEndRun(args: any) {
|
| 80 |
+
await setStatusText('end-to-end coverage: starting');
|
| 81 |
+
const res = await endToEndRun(
|
| 82 |
+
args.projectName,
|
| 83 |
+
args.secondsToRun,
|
| 84 |
+
args.vsContext
|
| 85 |
+
);
|
| 86 |
+
if (res) {
|
| 87 |
+
await setStatusText('end-to-end coverage: finished succesfully');
|
| 88 |
+
} else {
|
| 89 |
+
await setStatusText('end-to-end coverage: failed');
|
| 90 |
+
}
|
| 91 |
+
return;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
async function endToEndRun(
|
| 95 |
+
ossFuzzProjectNameInput: string,
|
| 96 |
+
secondsToRunEachFuzzer: string,
|
| 97 |
+
context: vscode.ExtensionContext
|
| 98 |
+
) {
|
| 99 |
+
await setStatusText('end-to-end coverage: build with ASAN');
|
| 100 |
+
vscode.window.showInformationMessage(
|
| 101 |
+
'Building project: ' + ossFuzzProjectNameInput.toString()
|
| 102 |
+
);
|
| 103 |
+
if (
|
| 104 |
+
(await buildFuzzersFromWorkspace(
|
| 105 |
+
ossFuzzProjectNameInput.toString(),
|
| 106 |
+
'',
|
| 107 |
+
true
|
| 108 |
+
)) === false
|
| 109 |
+
) {
|
| 110 |
+
println('Failed to build project');
|
| 111 |
+
return false;
|
| 112 |
+
}
|
| 113 |
+
println('Build projects');
|
| 114 |
+
|
| 115 |
+
// List all of the fuzzers in the project
|
| 116 |
+
const fuzzersInProject = await listFuzzersForProject(
|
| 117 |
+
ossFuzzProjectNameInput,
|
| 118 |
+
extensionConfig.ossFuzzPepositoryWorkPath
|
| 119 |
+
);
|
| 120 |
+
|
| 121 |
+
// Run all of the fuzzers in the project
|
| 122 |
+
await setStatusText('end-to-end coverage: collecting corpus');
|
| 123 |
+
println('Fuzzers found in project: ' + fuzzersInProject.toString());
|
| 124 |
+
println('Running each of the fuzzers to collect a corpus');
|
| 125 |
+
for (const fuzzName of fuzzersInProject) {
|
| 126 |
+
println('Running fuzzer: ' + fuzzName);
|
| 127 |
+
await setStatusText('end-to-end coverage: collecting corpus: ' + fuzzName);
|
| 128 |
+
// Corpus directory
|
| 129 |
+
const fuzzerCorpusPath =
|
| 130 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 131 |
+
'/build/corpus/' +
|
| 132 |
+
ossFuzzProjectNameInput +
|
| 133 |
+
'/' +
|
| 134 |
+
fuzzName;
|
| 135 |
+
|
| 136 |
+
await systemSync('mkdir', ['-p', fuzzerCorpusPath]);
|
| 137 |
+
|
| 138 |
+
await runFuzzerHandler(
|
| 139 |
+
ossFuzzProjectNameInput,
|
| 140 |
+
fuzzName,
|
| 141 |
+
secondsToRunEachFuzzer.toString(),
|
| 142 |
+
fuzzerCorpusPath
|
| 143 |
+
);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// Build with code coverage
|
| 147 |
+
println('Building project with coverage sanitizer');
|
| 148 |
+
await setStatusText('end-to-end coverage: building with coverage');
|
| 149 |
+
await buildFuzzersFromWorkspace(
|
| 150 |
+
ossFuzzProjectNameInput.toString(),
|
| 151 |
+
'coverage',
|
| 152 |
+
true
|
| 153 |
+
);
|
| 154 |
+
|
| 155 |
+
// Run coverage command
|
| 156 |
+
println('Collecting code coverage');
|
| 157 |
+
await setStatusText('end-to-end coverage: collecting coverage');
|
| 158 |
+
const args: Array<string> = [
|
| 159 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 160 |
+
'coverage',
|
| 161 |
+
'--port',
|
| 162 |
+
'',
|
| 163 |
+
'--no-corpus-download',
|
| 164 |
+
ossFuzzProjectNameInput.toString(),
|
| 165 |
+
];
|
| 166 |
+
await systemSync('python3', args);
|
| 167 |
+
await setStatusText('end-to-end coverage: finished collecting coverage');
|
| 168 |
+
println('Load coverage report with the command:');
|
| 169 |
+
println(
|
| 170 |
+
'python3 -m http.server 8008 --directory /tmp/oss-fuzz/build/out/' +
|
| 171 |
+
ossFuzzProjectNameInput.toString() +
|
| 172 |
+
'/report/'
|
| 173 |
+
);
|
| 174 |
+
|
| 175 |
+
println('Trying to load code coverage in IDE');
|
| 176 |
+
const allCovPath =
|
| 177 |
+
extensionConfig.ossFuzzPepositoryWorkPath +
|
| 178 |
+
'/build/out/' +
|
| 179 |
+
ossFuzzProjectNameInput.toString() +
|
| 180 |
+
'/textcov_reports/all_cov.json';
|
| 181 |
+
if (fs.existsSync(allCovPath)) {
|
| 182 |
+
const generatedCodeCoverageFile = vscode.Uri.file(allCovPath);
|
| 183 |
+
await loadCoverageIntoWorkspace(context, generatedCodeCoverageFile);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
await compareLocalToRemoteCoverage(
|
| 187 |
+
context,
|
| 188 |
+
ossFuzzProjectNameInput.toString()
|
| 189 |
+
);
|
| 190 |
+
|
| 191 |
+
return true;
|
| 192 |
+
}
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdRedo.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import {commandHistory} from '../commandUtils';
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Rerun the latest command
|
| 21 |
+
*/
|
| 22 |
+
export async function cmdDispatcherRe() {
|
| 23 |
+
if (commandHistory.length === 0) {
|
| 24 |
+
console.log('command history is empty');
|
| 25 |
+
return false;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const commandObj: any = commandHistory[commandHistory.length - 1];
|
| 29 |
+
|
| 30 |
+
console.log('Redoing');
|
| 31 |
+
console.log(commandObj.commandType);
|
| 32 |
+
await commandObj.dispatcherFunc(commandObj.Arguments);
|
| 33 |
+
//await commandObj.dispatcherFunc(commandObj.args);
|
| 34 |
+
return true;
|
| 35 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdReproduceTestcase.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
const fs = require('fs');
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {commandHistory} from '../commandUtils';
|
| 21 |
+
import {systemSyncLogIfFailure} from '../utils';
|
| 22 |
+
import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 23 |
+
import {extensionConfig} from '../config';
|
| 24 |
+
const readline = require('readline');
|
| 25 |
+
|
| 26 |
+
export async function cmdInputCollectorReproduceTestcase() {
|
| 27 |
+
// Runs a fuzzer from a given project.
|
| 28 |
+
const crashFileInput = await vscode.window.showInputBox({
|
| 29 |
+
value: '',
|
| 30 |
+
placeHolder: 'The ID of the testcase.',
|
| 31 |
+
});
|
| 32 |
+
if (!crashFileInput) {
|
| 33 |
+
return;
|
| 34 |
+
}
|
| 35 |
+
// Create an history object and append it to the command history.
|
| 36 |
+
const args = new Object({
|
| 37 |
+
crashFile: crashFileInput.toString(),
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
const commandObject = new Object({
|
| 41 |
+
commandType: 'oss-fuzz.ReproduceFuzzer',
|
| 42 |
+
Arguments: args,
|
| 43 |
+
dispatcherFunc: cmdDispatchReproduceTestcase,
|
| 44 |
+
});
|
| 45 |
+
commandHistory.push(commandObject);
|
| 46 |
+
|
| 47 |
+
await cmdDispatchReproduceTestcase(args);
|
| 48 |
+
return true;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
async function cmdDispatchReproduceTestcase(args: any) {
|
| 52 |
+
await reproduceTestcase(args.crashFile);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export async function reproduceTestcase(crashInfoFileInput: string) {
|
| 56 |
+
println('Reproducing testcase for ' + crashInfoFileInput);
|
| 57 |
+
println('Checking directory: ' + extensionConfig.crashesDirectory);
|
| 58 |
+
|
| 59 |
+
const crashInfoFile =
|
| 60 |
+
extensionConfig.crashesDirectory + '/' + crashInfoFileInput + '.info';
|
| 61 |
+
println(crashInfoFile);
|
| 62 |
+
try {
|
| 63 |
+
if (fs.existsSync(crashInfoFile)) {
|
| 64 |
+
println('File exists');
|
| 65 |
+
} else {
|
| 66 |
+
println('Crash file does not exist');
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
} catch (err) {
|
| 70 |
+
console.error(err);
|
| 71 |
+
return;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// At this point the file exists
|
| 75 |
+
const r = readline.createInterface({
|
| 76 |
+
input: fs.createReadStream(crashInfoFile),
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
let targetProject = 'N/A';
|
| 80 |
+
let targetFuzzer = 'N/A';
|
| 81 |
+
// Logic for passing the file. This is based off of clusterfuzz monorail reports,
|
| 82 |
+
// and the intention is the file needs to be a copy of:
|
| 83 |
+
//
|
| 84 |
+
// Project: project-name
|
| 85 |
+
// Fuzzing Engine: libFuzzer
|
| 86 |
+
// Fuzz Target: fuzzer-name
|
| 87 |
+
//
|
| 88 |
+
// Example:
|
| 89 |
+
// The following URL: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59747
|
| 90 |
+
// has the bug information:
|
| 91 |
+
// """
|
| 92 |
+
// Project: my-fuzzing-project
|
| 93 |
+
// Fuzzing Engine: libFuzzer
|
| 94 |
+
// Fuzz Target: the-fuzzer-name-fuzz-parseXX
|
| 95 |
+
// Job Type: libfuzzer_asan_my-fuzzing-project
|
| 96 |
+
// Platform Id: linux
|
| 97 |
+
// """
|
| 98 |
+
// and a link to a reproducer test case:
|
| 99 |
+
// https://oss-fuzz.com/download?testcase_id=5009071179431936
|
| 100 |
+
// which, when accessed will download the file
|
| 101 |
+
// clusterfuzz-testcase-minimized-flb-it-fuzz-config_map_fuzzer_OSSFUZZ-5009071179431936
|
| 102 |
+
//
|
| 103 |
+
// To enable reproducing of this issue we need to:
|
| 104 |
+
// - 1) Download the crash file and place it in the directory given in config.ts
|
| 105 |
+
// and "crashesDirectory" variable.
|
| 106 |
+
// - 2) create a file "5009071179431936.info" and paste the information above
|
| 107 |
+
// (Project:... Fuzz Target: ...) into the file. This information is
|
| 108 |
+
// needed because we need to know project name and fuzzer name in order
|
| 109 |
+
// to reproduce the crash.
|
| 110 |
+
// - 3) the reproducer can now be reproduced using the reproduce command
|
| 111 |
+
// with argument "5009071179431936" as argument.
|
| 112 |
+
r.on('line', (text: string) => {
|
| 113 |
+
println(text);
|
| 114 |
+
if (text.startsWith('Project: ')) {
|
| 115 |
+
println('Starts with project');
|
| 116 |
+
println(text.split('Project: ').toString());
|
| 117 |
+
targetProject = text.split('Project: ')[1];
|
| 118 |
+
} else if (text.startsWith('Fuzzing Engine: ')) {
|
| 119 |
+
println('Starts with fuzzing engine');
|
| 120 |
+
} else if (text.startsWith('Fuzz Target:')) {
|
| 121 |
+
println('Starts with Fuzz Target');
|
| 122 |
+
targetFuzzer = text.split('Fuzz Target: ')[1];
|
| 123 |
+
} else if (text.startsWith('Job Type:')) {
|
| 124 |
+
println('Starts with Job Type');
|
| 125 |
+
}
|
| 126 |
+
});
|
| 127 |
+
|
| 128 |
+
r.on('close', async () => {
|
| 129 |
+
println('Target project: ' + targetProject);
|
| 130 |
+
println('Target fuzzer: ' + targetFuzzer);
|
| 131 |
+
|
| 132 |
+
// Build a fresh version of the project.
|
| 133 |
+
const buildResult: boolean = await buildFuzzersFromWorkspace(
|
| 134 |
+
targetProject,
|
| 135 |
+
'',
|
| 136 |
+
true
|
| 137 |
+
);
|
| 138 |
+
if (!buildResult) {
|
| 139 |
+
println('Failed to build fuzzers');
|
| 140 |
+
return false;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// We have a fresh build of the project, proceed to reproduce the testcase.
|
| 144 |
+
const crashInputTestCase =
|
| 145 |
+
extensionConfig.crashesDirectory +
|
| 146 |
+
'/' +
|
| 147 |
+
'clusterfuzz-testcase-minimized-' +
|
| 148 |
+
targetFuzzer +
|
| 149 |
+
'-' +
|
| 150 |
+
crashInfoFileInput;
|
| 151 |
+
// Run reproduce command against the target file
|
| 152 |
+
// Build the fuzzers using OSS-Fuzz infrastructure.
|
| 153 |
+
const cmdToExec = 'python3';
|
| 154 |
+
const args = [
|
| 155 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py',
|
| 156 |
+
'reproduce',
|
| 157 |
+
targetProject,
|
| 158 |
+
targetFuzzer,
|
| 159 |
+
crashInputTestCase,
|
| 160 |
+
];
|
| 161 |
+
if (!(await systemSyncLogIfFailure(cmdToExec, args))) {
|
| 162 |
+
println('Failed to reproduce testcase');
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
return true;
|
| 166 |
+
});
|
| 167 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFI.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2024 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import {runFuzzIntrospector} from '../fuzzIntrospectorHelper';
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Function for setting up Fuzz Introspector by way of a Python virtual env.
|
| 21 |
+
*/
|
| 22 |
+
export async function runFuzzIntrospectorHandler() {
|
| 23 |
+
runFuzzIntrospector();
|
| 24 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdRunFuzzer.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {println} from '../logger';
|
| 19 |
+
import {commandHistory} from '../commandUtils';
|
| 20 |
+
import {runFuzzerHandler} from '../ossfuzzWrappers';
|
| 21 |
+
|
| 22 |
+
export async function cmdInputCollectorRunSpecificFuzzer() {
|
| 23 |
+
let projectNameArg = '';
|
| 24 |
+
let fuzzerName = '';
|
| 25 |
+
let secondsToRun = '';
|
| 26 |
+
|
| 27 |
+
// Runs a fuzzer from a given project.
|
| 28 |
+
const projectNameFromPrompt = await vscode.window.showInputBox({
|
| 29 |
+
value: '',
|
| 30 |
+
placeHolder: 'Type a project name',
|
| 31 |
+
});
|
| 32 |
+
if (!projectNameFromPrompt) {
|
| 33 |
+
println('Failed to get project name');
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
projectNameArg = projectNameFromPrompt.toString();
|
| 37 |
+
const fuzzerNameFromPrompt = await vscode.window.showInputBox({
|
| 38 |
+
value: '',
|
| 39 |
+
placeHolder: 'Type a fuzzer name',
|
| 40 |
+
});
|
| 41 |
+
if (!fuzzerNameFromPrompt) {
|
| 42 |
+
println('Failed to get fuzzer name');
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
fuzzerName = fuzzerNameFromPrompt.toString();
|
| 46 |
+
const secondsToRunInp = await vscode.window.showInputBox({
|
| 47 |
+
value: '',
|
| 48 |
+
placeHolder: 'Type the number of seconds to run the fuzzer',
|
| 49 |
+
});
|
| 50 |
+
if (!secondsToRunInp) {
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
secondsToRun = secondsToRunInp.toString();
|
| 54 |
+
|
| 55 |
+
// Create an history object
|
| 56 |
+
const args = new Object({
|
| 57 |
+
projectName: projectNameArg,
|
| 58 |
+
fuzzerName: fuzzerName,
|
| 59 |
+
secondsToRun: secondsToRun,
|
| 60 |
+
fuzzerCorpusPath: '',
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
const commandObject = new Object({
|
| 64 |
+
commandType: 'oss-fuzz.RunFuzzer',
|
| 65 |
+
Arguments: args,
|
| 66 |
+
dispatcherFunc: cmdDispatchRunFuzzerHandler,
|
| 67 |
+
});
|
| 68 |
+
console.log('L1: ' + commandHistory.length);
|
| 69 |
+
commandHistory.push(commandObject);
|
| 70 |
+
|
| 71 |
+
await cmdDispatchRunFuzzerHandler(args);
|
| 72 |
+
return true;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
async function cmdDispatchRunFuzzerHandler(args: any) {
|
| 76 |
+
await runFuzzerHandler(
|
| 77 |
+
args.projectName,
|
| 78 |
+
args.fuzzerName,
|
| 79 |
+
args.secondsToRun,
|
| 80 |
+
args.fuzzerCorpusPath
|
| 81 |
+
);
|
| 82 |
+
return;
|
| 83 |
+
}
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdSetupCIFuzz.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {println} from '../logger';
|
| 19 |
+
import {determineWorkspaceLanguage} from '../utils';
|
| 20 |
+
import {cifuzzGenerator} from '../cifuzz';
|
| 21 |
+
|
| 22 |
+
export async function setupCIFuzzHandler() {
|
| 23 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 24 |
+
if (!workspaceFolder) {
|
| 25 |
+
return false;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* Go through GitHub workflows to find potential traces of CIFuzz
|
| 32 |
+
*/
|
| 33 |
+
const githubWorkflowsPath = vscode.Uri.file(wsPath + '/.github/workflows');
|
| 34 |
+
try {
|
| 35 |
+
await vscode.workspace.fs.readDirectory(githubWorkflowsPath);
|
| 36 |
+
} catch {
|
| 37 |
+
println('Did not find a workflows path.');
|
| 38 |
+
return false;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
for (const [name, type] of await vscode.workspace.fs.readDirectory(
|
| 42 |
+
githubWorkflowsPath
|
| 43 |
+
)) {
|
| 44 |
+
// Skip directories.
|
| 45 |
+
if (type === 2) {
|
| 46 |
+
continue;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Read the files.
|
| 50 |
+
println('Is a file');
|
| 51 |
+
const workflowFile = vscode.Uri.file(wsPath + '/.github/workflows/' + name);
|
| 52 |
+
const doc = await vscode.workspace.openTextDocument(workflowFile);
|
| 53 |
+
if (doc.getText().includes('cifuzz')) {
|
| 54 |
+
println('Found existing CIFuzz, will not continue.');
|
| 55 |
+
return false;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
println('Did not find CIFuzz, creating one.');
|
| 60 |
+
const projectName = await vscode.window.showInputBox({
|
| 61 |
+
value: '',
|
| 62 |
+
placeHolder: 'OSS-Fuzz project name',
|
| 63 |
+
});
|
| 64 |
+
if (!projectName) {
|
| 65 |
+
println('Failed to get project name');
|
| 66 |
+
return false;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/*
|
| 70 |
+
* There is no CIFuzz found, so we create one.
|
| 71 |
+
*/
|
| 72 |
+
// Determine the language of the workspace.
|
| 73 |
+
const targetLanguage = await determineWorkspaceLanguage();
|
| 74 |
+
println('Target language: ' + targetLanguage);
|
| 75 |
+
|
| 76 |
+
// Generate a CIFuzz workflow text.
|
| 77 |
+
const cifuzzWorkflowText = cifuzzGenerator(targetLanguage, projectName, 30);
|
| 78 |
+
|
| 79 |
+
// Create the CIFuzz .yml file and write the contents to it to path
|
| 80 |
+
// .github/workflows/cifuzz.yml
|
| 81 |
+
const cifuzzYml = vscode.Uri.file(wsPath + '/.github/workflows/cifuzz.yml');
|
| 82 |
+
const wsedit = new vscode.WorkspaceEdit();
|
| 83 |
+
wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
|
| 84 |
+
wsedit.insert(cifuzzYml, new vscode.Position(0, 0), cifuzzWorkflowText);
|
| 85 |
+
vscode.workspace.applyEdit(wsedit);
|
| 86 |
+
return true;
|
| 87 |
+
}
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdTemplate.ts
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Command for generating template fuzzers. This is a short-cut for rapid
|
| 19 |
+
* prototyping as well as an archive for inspiration.
|
| 20 |
+
*/
|
| 21 |
+
import * as vscode from 'vscode';
|
| 22 |
+
import {println} from '../logger';
|
| 23 |
+
|
| 24 |
+
export const cLangSimpleStringFuzzer = `#include <stdint.h>
|
| 25 |
+
#include <string.h>
|
| 26 |
+
#include <stdlib.h>
|
| 27 |
+
|
| 28 |
+
int
|
| 29 |
+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
| 30 |
+
{
|
| 31 |
+
char *new_str = (char *)malloc(size+1);
|
| 32 |
+
if (new_str == NULL){
|
| 33 |
+
return 0;
|
| 34 |
+
}
|
| 35 |
+
memcpy(new_str, data, size);
|
| 36 |
+
new_str[size] = '\\0';
|
| 37 |
+
|
| 38 |
+
// Insert fuzzer contents here
|
| 39 |
+
// fuzz data in new_str
|
| 40 |
+
|
| 41 |
+
// end of fuzzer contents
|
| 42 |
+
|
| 43 |
+
free(new_str);
|
| 44 |
+
return 0;
|
| 45 |
+
}`;
|
| 46 |
+
|
| 47 |
+
const cLangFileInputFuzzer = `int
|
| 48 |
+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
| 49 |
+
{
|
| 50 |
+
char filename[256];
|
| 51 |
+
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
|
| 52 |
+
|
| 53 |
+
// Create a file on the filesystem with fuzzer data in it
|
| 54 |
+
FILE *fp = fopen(filename, "wb");
|
| 55 |
+
if (!fp) {
|
| 56 |
+
return 0;
|
| 57 |
+
}
|
| 58 |
+
fwrite(data, size, 1, fp);
|
| 59 |
+
fclose(fp);
|
| 60 |
+
|
| 61 |
+
// Fuzzer logic here. Use the file as a source of data.
|
| 62 |
+
|
| 63 |
+
// Fuzzer logic end
|
| 64 |
+
|
| 65 |
+
// Clean up the file.
|
| 66 |
+
unlink(filename);
|
| 67 |
+
|
| 68 |
+
return 0;
|
| 69 |
+
}`;
|
| 70 |
+
|
| 71 |
+
const cLangBareTemplateFuzzer = `int
|
| 72 |
+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
| 73 |
+
{
|
| 74 |
+
return 0;
|
| 75 |
+
}`;
|
| 76 |
+
|
| 77 |
+
const cppLangBareTemplateFuzzer = `extern "C" int
|
| 78 |
+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
| 79 |
+
{
|
| 80 |
+
return 0;
|
| 81 |
+
}`;
|
| 82 |
+
|
| 83 |
+
const cppLangStdStringTemplateFuzzer = `extern "C" int
|
| 84 |
+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
| 85 |
+
{
|
| 86 |
+
std::string input(reinterpret_cast<const char*>(data), size);
|
| 87 |
+
|
| 88 |
+
return 0;
|
| 89 |
+
}`;
|
| 90 |
+
|
| 91 |
+
export const cppLangFDPTemplateFuzzer = `#include <fuzzer/FuzzedDataProvider.h>
|
| 92 |
+
|
| 93 |
+
#include <string>
|
| 94 |
+
|
| 95 |
+
extern "C" int
|
| 96 |
+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
| 97 |
+
{
|
| 98 |
+
FuzzedDataProvider fdp(data, size);
|
| 99 |
+
|
| 100 |
+
// Extract higher level data types used for fuzzing, e.g.
|
| 101 |
+
// int ran_int = fdp.ConsumeIntegralInRange<int>(1, 1024);
|
| 102 |
+
// std::string s = fdp.ConsumeRandomLengthString();
|
| 103 |
+
|
| 104 |
+
return 0;
|
| 105 |
+
}`;
|
| 106 |
+
|
| 107 |
+
const cppLangFileInputFuzzer = `extern "C" int
|
| 108 |
+
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
| 109 |
+
{
|
| 110 |
+
char filename[256];
|
| 111 |
+
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
|
| 112 |
+
|
| 113 |
+
FILE *fp = fopen(filename, "wb");
|
| 114 |
+
if (!fp) {
|
| 115 |
+
return 0;
|
| 116 |
+
}
|
| 117 |
+
fwrite(data, size, 1, fp);
|
| 118 |
+
fclose(fp);
|
| 119 |
+
|
| 120 |
+
// Fuzzer logic here
|
| 121 |
+
|
| 122 |
+
// Fuzzer logic end
|
| 123 |
+
|
| 124 |
+
unlink(filename);
|
| 125 |
+
}`;
|
| 126 |
+
|
| 127 |
+
const pythonLangBareTemplate = `import sys
|
| 128 |
+
import atheris
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def TestOneInput(fuzz_bytes):
|
| 132 |
+
return
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def main():
|
| 136 |
+
atheris.Setup(sys.argv, TestOneInput)
|
| 137 |
+
atheris.Fuzz()
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
if __name__ == "__main__":
|
| 141 |
+
main()`;
|
| 142 |
+
|
| 143 |
+
export const pythonLangFileInputFuzzer = `import sys
|
| 144 |
+
import atheris
|
| 145 |
+
|
| 146 |
+
@atheris.instrument_func
|
| 147 |
+
def TestOneInput(data):
|
| 148 |
+
# Write fuzz data to a file
|
| 149 |
+
with open('/tmp/fuzz_input.b') as f:
|
| 150 |
+
f.write(data)
|
| 151 |
+
|
| 152 |
+
# Use '/tmp/fuzz_input.b' as input to file handling logic.
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def main():
|
| 156 |
+
atheris.instrument_all()
|
| 157 |
+
atheris.Setup(sys.argv, TestOneInput)
|
| 158 |
+
atheris.Fuzz()
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
if __name__ == "__main__":
|
| 162 |
+
main()`;
|
| 163 |
+
|
| 164 |
+
const pythonLongFdpTemplate = `import sys
|
| 165 |
+
import atheris
|
| 166 |
+
|
| 167 |
+
def TestOneInput(fuzz_bytes):
|
| 168 |
+
fdp = atheris.FuzzedDataProvider(fuzz_bytes)
|
| 169 |
+
return
|
| 170 |
+
|
| 171 |
+
def main():
|
| 172 |
+
atheris.Setup(sys.argv, TestOneInput)
|
| 173 |
+
atheris.Fuzz()
|
| 174 |
+
|
| 175 |
+
if __name__ == "__main__":
|
| 176 |
+
main()`;
|
| 177 |
+
|
| 178 |
+
export const javaLangBareTemplate = `import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
| 179 |
+
public class SampleFuzzer {
|
| 180 |
+
public static void fuzzerTestOneInput(FuzzedDataProvider fdp) {
|
| 181 |
+
// Use fdp to create arbitrary types seeded with fuzz data
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
`;
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* C templates
|
| 188 |
+
*/
|
| 189 |
+
async function cTemplates() {
|
| 190 |
+
let template = '';
|
| 191 |
+
const result = await vscode.window.showQuickPick(
|
| 192 |
+
['Bare template', 'Null-terminated string input', 'File input'],
|
| 193 |
+
{
|
| 194 |
+
placeHolder: 'Pick which template',
|
| 195 |
+
}
|
| 196 |
+
);
|
| 197 |
+
vscode.window.showInformationMessage(`Got: ${result}`);
|
| 198 |
+
|
| 199 |
+
if (result === 'Null-terminated string input') {
|
| 200 |
+
template = cLangSimpleStringFuzzer;
|
| 201 |
+
} else if (result === 'File input') {
|
| 202 |
+
template = cLangFileInputFuzzer;
|
| 203 |
+
} else if (result === 'Bare template') {
|
| 204 |
+
template = cLangBareTemplateFuzzer;
|
| 205 |
+
} else {
|
| 206 |
+
template = 'empty';
|
| 207 |
+
}
|
| 208 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 209 |
+
if (!workspaceFolder) {
|
| 210 |
+
return;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 214 |
+
|
| 215 |
+
const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.c');
|
| 216 |
+
const wsedit = new vscode.WorkspaceEdit();
|
| 217 |
+
wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
|
| 218 |
+
wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
|
| 219 |
+
vscode.workspace.applyEdit(wsedit);
|
| 220 |
+
return;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
/**
|
| 224 |
+
* CPP templates
|
| 225 |
+
*/
|
| 226 |
+
async function cppTemplates() {
|
| 227 |
+
let template = '';
|
| 228 |
+
const result = await vscode.window.showQuickPick(
|
| 229 |
+
[
|
| 230 |
+
'Bare template',
|
| 231 |
+
'Simple CPP string',
|
| 232 |
+
'File input fuzzer',
|
| 233 |
+
'Fuzzed data provider',
|
| 234 |
+
],
|
| 235 |
+
{
|
| 236 |
+
placeHolder: 'Pick which template',
|
| 237 |
+
}
|
| 238 |
+
);
|
| 239 |
+
vscode.window.showInformationMessage(`Got: ${result}`);
|
| 240 |
+
|
| 241 |
+
if (result === 'Bare template') {
|
| 242 |
+
template = cppLangBareTemplateFuzzer;
|
| 243 |
+
} else if (result === 'Simple CPP string') {
|
| 244 |
+
template = cppLangStdStringTemplateFuzzer;
|
| 245 |
+
} else if (result === 'File input fuzzer') {
|
| 246 |
+
template = cppLangFileInputFuzzer;
|
| 247 |
+
} else if (result === 'Fuzzed data provider') {
|
| 248 |
+
template = cppLangFDPTemplateFuzzer;
|
| 249 |
+
} else {
|
| 250 |
+
template = 'empty';
|
| 251 |
+
}
|
| 252 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 253 |
+
if (!workspaceFolder) {
|
| 254 |
+
return;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 258 |
+
|
| 259 |
+
const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.cpp');
|
| 260 |
+
const wsedit = new vscode.WorkspaceEdit();
|
| 261 |
+
wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
|
| 262 |
+
wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
|
| 263 |
+
vscode.workspace.applyEdit(wsedit);
|
| 264 |
+
return;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
/**
|
| 268 |
+
* Python templates
|
| 269 |
+
*/
|
| 270 |
+
async function pythonTepmlates() {
|
| 271 |
+
let template = '';
|
| 272 |
+
const result = await vscode.window.showQuickPick(
|
| 273 |
+
['Bare template', 'Fuzzed Data Provider', 'File input fuzzer'],
|
| 274 |
+
{
|
| 275 |
+
placeHolder: 'Pick which template',
|
| 276 |
+
}
|
| 277 |
+
);
|
| 278 |
+
vscode.window.showInformationMessage(`Got: ${result}`);
|
| 279 |
+
|
| 280 |
+
if (result === 'Fuzzed Data Provider') {
|
| 281 |
+
template = pythonLongFdpTemplate;
|
| 282 |
+
} else if (result === 'Bare template') {
|
| 283 |
+
template = pythonLangBareTemplate;
|
| 284 |
+
} else if (result === 'File input fuzzer') {
|
| 285 |
+
template = pythonLangFileInputFuzzer;
|
| 286 |
+
} else {
|
| 287 |
+
template = 'empty';
|
| 288 |
+
}
|
| 289 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 290 |
+
if (!workspaceFolder) {
|
| 291 |
+
return;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 295 |
+
|
| 296 |
+
const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.py');
|
| 297 |
+
const wsedit = new vscode.WorkspaceEdit();
|
| 298 |
+
wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
|
| 299 |
+
wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
|
| 300 |
+
vscode.workspace.applyEdit(wsedit);
|
| 301 |
+
return;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
/**
|
| 305 |
+
* Java templates
|
| 306 |
+
*/
|
| 307 |
+
async function javaTemplates() {
|
| 308 |
+
let template = '';
|
| 309 |
+
const result = await vscode.window.showQuickPick(['Bare template'], {
|
| 310 |
+
placeHolder: 'Pick which template',
|
| 311 |
+
});
|
| 312 |
+
vscode.window.showInformationMessage(`Got: ${result}`);
|
| 313 |
+
|
| 314 |
+
if (result === 'Bare template') {
|
| 315 |
+
template = javaLangBareTemplate;
|
| 316 |
+
} else {
|
| 317 |
+
template = 'empty';
|
| 318 |
+
}
|
| 319 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 320 |
+
if (!workspaceFolder) {
|
| 321 |
+
return;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 325 |
+
|
| 326 |
+
const cifuzzYml = vscode.Uri.file(wsPath + '/oss-fuzz-template.java');
|
| 327 |
+
const wsedit = new vscode.WorkspaceEdit();
|
| 328 |
+
wsedit.createFile(cifuzzYml, {ignoreIfExists: true});
|
| 329 |
+
wsedit.insert(cifuzzYml, new vscode.Position(0, 0), template);
|
| 330 |
+
vscode.workspace.applyEdit(wsedit);
|
| 331 |
+
return;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
export async function cmdDispatcherTemplate(context: vscode.ExtensionContext) {
|
| 335 |
+
println('Creating template');
|
| 336 |
+
const options: {
|
| 337 |
+
[key: string]: (context: vscode.ExtensionContext) => Promise<void>;
|
| 338 |
+
} = {
|
| 339 |
+
C: cTemplates,
|
| 340 |
+
CPP: cppTemplates,
|
| 341 |
+
Python: pythonTepmlates,
|
| 342 |
+
Java: javaTemplates,
|
| 343 |
+
};
|
| 344 |
+
|
| 345 |
+
const quickPick = vscode.window.createQuickPick();
|
| 346 |
+
quickPick.items = Object.keys(options).map(label => ({label}));
|
| 347 |
+
quickPick.onDidChangeSelection(selection => {
|
| 348 |
+
if (selection[0]) {
|
| 349 |
+
options[selection[0].label](context).catch(console.error);
|
| 350 |
+
}
|
| 351 |
+
});
|
| 352 |
+
quickPick.onDidHide(() => quickPick.dispose());
|
| 353 |
+
quickPick.placeholder = 'Pick language';
|
| 354 |
+
quickPick.show();
|
| 355 |
+
|
| 356 |
+
return;
|
| 357 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzer.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {println} from '../logger';
|
| 19 |
+
import {runFuzzerHandler, buildFuzzersFromWorkspace} from '../ossfuzzWrappers';
|
| 20 |
+
import {setStatusText} from '../utils';
|
| 21 |
+
import {commandHistory} from '../commandUtils';
|
| 22 |
+
import {extensionConfig} from '../config';
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Does an end-to-end test of a project/fuzzer. This is done by
|
| 26 |
+
* first building the project and then running the fuzzer.
|
| 27 |
+
* @param context
|
| 28 |
+
* @returns
|
| 29 |
+
*/
|
| 30 |
+
|
| 31 |
+
export async function cmdInputCollectorTestFuzzer() {
|
| 32 |
+
setStatusText('Testing specific fuzzer: getting input');
|
| 33 |
+
// Get the project name and fuzzer name to test.
|
| 34 |
+
const ossFuzzProjectNameInput = await vscode.window.showInputBox({
|
| 35 |
+
value: '',
|
| 36 |
+
placeHolder: 'The OSS-Fuzz project name',
|
| 37 |
+
});
|
| 38 |
+
if (!ossFuzzProjectNameInput) {
|
| 39 |
+
println('Did not get a ossFuzzTargetProject');
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
println('Project name: ' + ossFuzzProjectNameInput);
|
| 43 |
+
|
| 44 |
+
// Get the fuzzer to run
|
| 45 |
+
const fuzzerNameInput = await vscode.window.showInputBox({
|
| 46 |
+
value: '',
|
| 47 |
+
placeHolder: 'Type a fuzzer name',
|
| 48 |
+
});
|
| 49 |
+
if (!fuzzerNameInput) {
|
| 50 |
+
println('Failed to get fuzzer name');
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Create the args object for the dispatcher
|
| 55 |
+
const args = new Object({
|
| 56 |
+
projectName: ossFuzzProjectNameInput.toString(),
|
| 57 |
+
fuzzerName: fuzzerNameInput.toString(),
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
// Create a dispatcher object.
|
| 61 |
+
const commandObject = new Object({
|
| 62 |
+
commandType: 'oss-fuzz.TestFuzzer',
|
| 63 |
+
Arguments: args,
|
| 64 |
+
dispatcherFunc: cmdDispatchTestFuzzerHandler,
|
| 65 |
+
});
|
| 66 |
+
commandHistory.push(commandObject);
|
| 67 |
+
|
| 68 |
+
await cmdDispatchTestFuzzerHandler(args);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
async function cmdDispatchTestFuzzerHandler(args: any) {
|
| 72 |
+
// Build the project
|
| 73 |
+
setStatusText('Test specific fuzzer: building fuzzers in workspace');
|
| 74 |
+
if (!(await buildFuzzersFromWorkspace(args.projectName, '', false))) {
|
| 75 |
+
println('Build projects');
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Run the fuzzer for 10 seconds
|
| 80 |
+
println('Running fuzzer');
|
| 81 |
+
setStatusText('Test specific fuzzer: running fuzzer ' + args.fuzzerName);
|
| 82 |
+
await runFuzzerHandler(
|
| 83 |
+
args.projectName,
|
| 84 |
+
args.fuzzerName,
|
| 85 |
+
extensionConfig.numberOfSecondsForTestRuns.toString(),
|
| 86 |
+
''
|
| 87 |
+
);
|
| 88 |
+
setStatusText('Test specific fuzzer: test completed of ' + args.fuzzerName);
|
| 89 |
+
return;
|
| 90 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/commands/cmdTestFuzzerCFLite.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import path = require('path');
|
| 18 |
+
import * as vscode from 'vscode';
|
| 19 |
+
import {println} from '../logger';
|
| 20 |
+
import {
|
| 21 |
+
runFuzzerHandlerCFLite,
|
| 22 |
+
buildFuzzersFromWorkspaceClusterfuzzLite,
|
| 23 |
+
} from '../ossfuzzWrappers';
|
| 24 |
+
import {setStatusText} from '../utils';
|
| 25 |
+
import {commandHistory} from '../commandUtils';
|
| 26 |
+
import {extensionConfig} from '../config';
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Does an end-to-end test of a project/fuzzer. This is done by
|
| 30 |
+
* first building the project and then running the fuzzer.
|
| 31 |
+
* @param context
|
| 32 |
+
* @returns
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
export async function cmdInputCollectorTestFuzzerCFLite() {
|
| 36 |
+
setStatusText('Testing specific fuzzer: getting input');
|
| 37 |
+
// Get the fuzzer to run
|
| 38 |
+
const fuzzerNameInput = await vscode.window.showInputBox({
|
| 39 |
+
value: '',
|
| 40 |
+
placeHolder: 'Type a fuzzer name',
|
| 41 |
+
});
|
| 42 |
+
if (!fuzzerNameInput) {
|
| 43 |
+
println('Failed to get fuzzer name');
|
| 44 |
+
return;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
// Create the args object for the dispatcher
|
| 48 |
+
const args = new Object({
|
| 49 |
+
fuzzerName: fuzzerNameInput.toString(),
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
// Create a dispatcher object.
|
| 53 |
+
const commandObject = new Object({
|
| 54 |
+
commandType: 'oss-fuzz.TestFuzzerCFLite',
|
| 55 |
+
Arguments: args,
|
| 56 |
+
dispatcherFunc: cmdDispatchTestFuzzerHandlerCFLite,
|
| 57 |
+
});
|
| 58 |
+
commandHistory.push(commandObject);
|
| 59 |
+
|
| 60 |
+
await cmdDispatchTestFuzzerHandlerCFLite(args);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
async function cmdDispatchTestFuzzerHandlerCFLite(args: any) {
|
| 64 |
+
// Build the project
|
| 65 |
+
setStatusText('Test specific fuzzer: building fuzzers in workspace');
|
| 66 |
+
if (!(await buildFuzzersFromWorkspaceClusterfuzzLite())) {
|
| 67 |
+
println('Build projects');
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 72 |
+
if (!workspaceFolder) {
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
const pathOfLocal = workspaceFolder[0].uri.path;
|
| 77 |
+
println('path of local: ' + pathOfLocal);
|
| 78 |
+
|
| 79 |
+
// Run the fuzzer for 10 seconds
|
| 80 |
+
println('Running fuzzer');
|
| 81 |
+
setStatusText('Test specific fuzzer: running fuzzer ' + args.fuzzerName);
|
| 82 |
+
await runFuzzerHandlerCFLite(
|
| 83 |
+
pathOfLocal,
|
| 84 |
+
args.fuzzerName,
|
| 85 |
+
extensionConfig.numberOfSecondsForTestRuns.toString()
|
| 86 |
+
);
|
| 87 |
+
setStatusText('Test specific fuzzer: test completed of ' + args.fuzzerName);
|
| 88 |
+
return;
|
| 89 |
+
}
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/extension.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
|
| 19 |
+
import {clearCoverage} from './coverageHelper';
|
| 20 |
+
import {println} from './logger';
|
| 21 |
+
|
| 22 |
+
// Import the command dispatcher functions
|
| 23 |
+
import {cmdInputCollectorRunSpecificFuzzer} from './commands/cmdRunFuzzer';
|
| 24 |
+
import {cmdInputCollectorBuildFuzzersFromWorkspace} from './commands/cmdBuildFuzzerFromWorkspace';
|
| 25 |
+
import {cmdInputCollectorBuildFuzzersFromWorkspaceCFLite} from './commands/cmdBuildFuzzerFromWorkspaceCFLite';
|
| 26 |
+
import {cmdInputCollectorTestFuzzerCFLite} from './commands/cmdTestFuzzerCFLite';
|
| 27 |
+
import {cmdDispatcherRe} from './commands/cmdRedo';
|
| 28 |
+
import {setupCIFuzzHandler} from './commands/cmdSetupCIFuzz';
|
| 29 |
+
import {cmdInputCollectorTestFuzzer} from './commands/cmdTestFuzzer';
|
| 30 |
+
import {displayCodeCoverageFromOssFuzz} from './commands/cmdDisplayCoverage';
|
| 31 |
+
import {createOssFuzzSetup} from './commands/cmdCreateOSSFuzzSetup';
|
| 32 |
+
import {runEndToEndAndGetCoverage} from './commands/cmdEndToEndCoverage';
|
| 33 |
+
import {listFuzzersHandler} from './commands/cmdListFuzzers';
|
| 34 |
+
import {cmdInputCollectorReproduceTestcase} from './commands/cmdReproduceTestcase';
|
| 35 |
+
import {cmdDispatcherTemplate} from './commands/cmdTemplate';
|
| 36 |
+
import {runGetOptimalTargetsHandler} from './commands/cmdFIGetOptimalTargets';
|
| 37 |
+
import {setUpFuzzIntrospectorHandler} from './commands/cmdSetupFI';
|
| 38 |
+
import {runFuzzIntrospectorHandler} from './commands/cmdRunFI';
|
| 39 |
+
import {cmdDispatcherGenerateClusterfuzzLite} from './commands/cmdDispatcherGenerateClusterfuzzLite';
|
| 40 |
+
import {setUpOssFuzzHandler} from './commands/cmdSetupOSSFuzz';
|
| 41 |
+
import {setOssFuzzPath} from './commands/cmdSetOSSFuzzPath';
|
| 42 |
+
import {extensionConfig} from './config';
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Extension entrypoint. Activate the extension and register the commands.
|
| 46 |
+
*/
|
| 47 |
+
export function activate(context: vscode.ExtensionContext) {
|
| 48 |
+
console.log('Activating extension)');
|
| 49 |
+
extensionConfig.printConfig();
|
| 50 |
+
println('OSS-Fuzz extension is now active!');
|
| 51 |
+
|
| 52 |
+
// Command registration
|
| 53 |
+
context.subscriptions.push(
|
| 54 |
+
vscode.commands.registerCommand('oss-fuzz.SetUp', async () => {
|
| 55 |
+
println('CMD start: SetUp');
|
| 56 |
+
await setUpOssFuzzHandler();
|
| 57 |
+
println('CMD end: SetUp');
|
| 58 |
+
})
|
| 59 |
+
);
|
| 60 |
+
|
| 61 |
+
context.subscriptions.push(
|
| 62 |
+
vscode.commands.registerCommand('oss-fuzz.RunFuzzer', async () => {
|
| 63 |
+
println('CMD start: Run Fuzzer');
|
| 64 |
+
//await runFuzzerHandler('', '', '', '');
|
| 65 |
+
cmdInputCollectorRunSpecificFuzzer();
|
| 66 |
+
println('CMD end: Run Fuzzer');
|
| 67 |
+
})
|
| 68 |
+
);
|
| 69 |
+
|
| 70 |
+
context.subscriptions.push(
|
| 71 |
+
vscode.commands.registerCommand('oss-fuzz.ListFuzzers', async () => {
|
| 72 |
+
println('CMD start: ListFuzzers');
|
| 73 |
+
await listFuzzersHandler();
|
| 74 |
+
println('CMD end: ListFuzzers');
|
| 75 |
+
})
|
| 76 |
+
);
|
| 77 |
+
|
| 78 |
+
context.subscriptions.push(
|
| 79 |
+
vscode.commands.registerCommand('oss-fuzz.SetOSSFuzzPath', async () => {
|
| 80 |
+
println('CMD start: SetOSSFuzzPath');
|
| 81 |
+
await setOssFuzzPath();
|
| 82 |
+
println('CMD end: SetOSSFuzzPath');
|
| 83 |
+
})
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
context.subscriptions.push(
|
| 87 |
+
vscode.commands.registerCommand('oss-fuzz.GetCodeCoverage', async () => {
|
| 88 |
+
println('CMD start: GetCodeCoverage');
|
| 89 |
+
await displayCodeCoverageFromOssFuzz(context);
|
| 90 |
+
println('CMD end: GetCodeCoverage');
|
| 91 |
+
})
|
| 92 |
+
);
|
| 93 |
+
|
| 94 |
+
context.subscriptions.push(
|
| 95 |
+
vscode.commands.registerCommand('oss-fuzz.ClearCodeCoverage', async () => {
|
| 96 |
+
println('CMD start: ClearCodeCoverage');
|
| 97 |
+
await clearCoverage();
|
| 98 |
+
println('CMD end: ClearCodeCoverage');
|
| 99 |
+
})
|
| 100 |
+
);
|
| 101 |
+
|
| 102 |
+
context.subscriptions.push(
|
| 103 |
+
vscode.commands.registerCommand('oss-fuzz.CreateOSSFuzzSetup', async () => {
|
| 104 |
+
println('CMD start: CreateOSSFuzzSetup');
|
| 105 |
+
await createOssFuzzSetup();
|
| 106 |
+
println('CMD end: CreateOSSFuzzSetup');
|
| 107 |
+
})
|
| 108 |
+
);
|
| 109 |
+
|
| 110 |
+
context.subscriptions.push(
|
| 111 |
+
vscode.commands.registerCommand('oss-fuzz.WSBuildFuzzers', async () => {
|
| 112 |
+
println('CMD start: WSBuildFuzzers3');
|
| 113 |
+
await cmdInputCollectorBuildFuzzersFromWorkspace();
|
| 114 |
+
println('CMD end: WSBuildFuzzers4');
|
| 115 |
+
})
|
| 116 |
+
);
|
| 117 |
+
|
| 118 |
+
context.subscriptions.push(
|
| 119 |
+
vscode.commands.registerCommand('oss-fuzz.SetupCIFuzz', async () => {
|
| 120 |
+
println('CMD start: SetupCIFuzz');
|
| 121 |
+
await setupCIFuzzHandler();
|
| 122 |
+
println('CMD end: SetupCIFuzz');
|
| 123 |
+
})
|
| 124 |
+
);
|
| 125 |
+
|
| 126 |
+
context.subscriptions.push(
|
| 127 |
+
vscode.commands.registerCommand('oss-fuzz.testFuzzer', async () => {
|
| 128 |
+
println('CMD start: testFuzzer');
|
| 129 |
+
await cmdInputCollectorTestFuzzer();
|
| 130 |
+
println('CMD end: testFuzzer');
|
| 131 |
+
})
|
| 132 |
+
);
|
| 133 |
+
|
| 134 |
+
context.subscriptions.push(
|
| 135 |
+
vscode.commands.registerCommand('oss-fuzz.testCodeCoverage', async () => {
|
| 136 |
+
println('CMD start: testCodeCoverage');
|
| 137 |
+
await runEndToEndAndGetCoverage(context);
|
| 138 |
+
println('CMD end: testCodeCoverage');
|
| 139 |
+
})
|
| 140 |
+
);
|
| 141 |
+
|
| 142 |
+
context.subscriptions.push(
|
| 143 |
+
vscode.commands.registerCommand('oss-fuzz.Reproduce', async () => {
|
| 144 |
+
println('CMD start: Reproduce');
|
| 145 |
+
await cmdInputCollectorReproduceTestcase();
|
| 146 |
+
println('CMD end: Reproduce');
|
| 147 |
+
})
|
| 148 |
+
);
|
| 149 |
+
|
| 150 |
+
context.subscriptions.push(
|
| 151 |
+
vscode.commands.registerCommand('oss-fuzz.Redo', async () => {
|
| 152 |
+
println('CMD start: Re');
|
| 153 |
+
await cmdDispatcherRe();
|
| 154 |
+
println('CMD end: Re');
|
| 155 |
+
})
|
| 156 |
+
);
|
| 157 |
+
|
| 158 |
+
context.subscriptions.push(
|
| 159 |
+
vscode.commands.registerCommand('oss-fuzz.Template', async () => {
|
| 160 |
+
println('CMD start: remplate');
|
| 161 |
+
await cmdDispatcherTemplate(context);
|
| 162 |
+
println('CMD end: template');
|
| 163 |
+
})
|
| 164 |
+
);
|
| 165 |
+
|
| 166 |
+
context.subscriptions.push(
|
| 167 |
+
vscode.commands.registerCommand(
|
| 168 |
+
'oss-fuzz.GenerateClusterfuzzLite',
|
| 169 |
+
async () => {
|
| 170 |
+
println('CMD start: GenerateClusterfuzzLite');
|
| 171 |
+
await cmdDispatcherGenerateClusterfuzzLite(context);
|
| 172 |
+
println('CMD end: GenerateClusterfuzzLite');
|
| 173 |
+
}
|
| 174 |
+
)
|
| 175 |
+
);
|
| 176 |
+
|
| 177 |
+
context.subscriptions.push(
|
| 178 |
+
vscode.commands.registerCommand(
|
| 179 |
+
'oss-fuzz.WSBuildFuzzersCFLite',
|
| 180 |
+
async () => {
|
| 181 |
+
println('CMD start: WSBuildFuzzersCFLite');
|
| 182 |
+
await cmdInputCollectorBuildFuzzersFromWorkspaceCFLite();
|
| 183 |
+
println('CMD end: WSBuildFuzzersCFLite');
|
| 184 |
+
}
|
| 185 |
+
)
|
| 186 |
+
);
|
| 187 |
+
|
| 188 |
+
context.subscriptions.push(
|
| 189 |
+
vscode.commands.registerCommand('oss-fuzz.testFuzzerCFLite', async () => {
|
| 190 |
+
println('CMD start: testFuzzerCFLite');
|
| 191 |
+
await cmdInputCollectorTestFuzzerCFLite();
|
| 192 |
+
println('CMD end: testFuzzerCFLite');
|
| 193 |
+
})
|
| 194 |
+
);
|
| 195 |
+
|
| 196 |
+
context.subscriptions.push(
|
| 197 |
+
vscode.commands.registerCommand(
|
| 198 |
+
'oss-fuzz.setupFuzzIntrospector',
|
| 199 |
+
async () => {
|
| 200 |
+
println('CMD start: setup FI');
|
| 201 |
+
await setUpFuzzIntrospectorHandler();
|
| 202 |
+
}
|
| 203 |
+
)
|
| 204 |
+
);
|
| 205 |
+
|
| 206 |
+
context.subscriptions.push(
|
| 207 |
+
vscode.commands.registerCommand(
|
| 208 |
+
'oss-fuzz.runFuzzIntrospector',
|
| 209 |
+
async () => {
|
| 210 |
+
println('CMD start: run Fuzz Introspector');
|
| 211 |
+
await runFuzzIntrospectorHandler();
|
| 212 |
+
}
|
| 213 |
+
)
|
| 214 |
+
);
|
| 215 |
+
|
| 216 |
+
context.subscriptions.push(
|
| 217 |
+
vscode.commands.registerCommand('oss-fuzz.GetOptimalTargets', async () => {
|
| 218 |
+
println('CMD start: run GetOptimalTargets');
|
| 219 |
+
await runGetOptimalTargetsHandler();
|
| 220 |
+
})
|
| 221 |
+
);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
// This method is called when your extension is deactivated
|
| 225 |
+
export function deactivate() {
|
| 226 |
+
println('Deactivating the extension');
|
| 227 |
+
}
|
local-test-tika-full-01-vuln_7/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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/ossfuzzWrappers.ts
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/projectIntegrationHelper.ts
ADDED
|
@@ -0,0 +1,761 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
const fs = require('fs');
|
| 19 |
+
import 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
|
| 760 |
+
createReadmeFile(wsedit, wsPath, baseFolder, isOssFuzz);
|
| 761 |
+
}
|
local-test-tika-full-01-vuln_7/fuzz-tooling/tools/vscode-extension/src/utils.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
//
|
| 15 |
+
////////////////////////////////////////////////////////////////////////////////
|
| 16 |
+
|
| 17 |
+
import * as vscode from 'vscode';
|
| 18 |
+
import {extensionConfig} from './config';
|
| 19 |
+
import {getApi, FileDownloader} from '@microsoft/vscode-file-downloader-api';
|
| 20 |
+
|
| 21 |
+
const fs = require('fs');
|
| 22 |
+
const {spawn} = require('node:child_process');
|
| 23 |
+
const statusBarComp = vscode.window.createStatusBarItem(
|
| 24 |
+
vscode.StatusBarAlignment.Right,
|
| 25 |
+
100
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
import {println, printRaw, debugPrintln} from './logger';
|
| 29 |
+
|
| 30 |
+
export async function setStatusText(statusText: string) {
|
| 31 |
+
//let myStatusBarItem: vscode.StatusBarItem;
|
| 32 |
+
statusBarComp.text = '$(megaphone) OSS-Fuzz: ' + statusText;
|
| 33 |
+
statusBarComp.show();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export async function downloadRemoteURL(
|
| 37 |
+
urlString: string,
|
| 38 |
+
targetFile: string,
|
| 39 |
+
context: vscode.ExtensionContext
|
| 40 |
+
) {
|
| 41 |
+
const fileDownloader: FileDownloader = await getApi();
|
| 42 |
+
println('URL: ' + urlString);
|
| 43 |
+
let codeCoverageFile: vscode.Uri;
|
| 44 |
+
try {
|
| 45 |
+
codeCoverageFile = await fileDownloader.downloadFile(
|
| 46 |
+
vscode.Uri.parse(urlString),
|
| 47 |
+
targetFile,
|
| 48 |
+
context
|
| 49 |
+
);
|
| 50 |
+
} catch (err) {
|
| 51 |
+
println('Could not get the coverage summary file');
|
| 52 |
+
return false;
|
| 53 |
+
}
|
| 54 |
+
return codeCoverageFile;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
export async function getLocalOutBuildDir(projectName: string) {
|
| 58 |
+
const summaryCovPath =
|
| 59 |
+
extensionConfig.ossFuzzPepositoryWorkPath + '/build/out/' + projectName;
|
| 60 |
+
return summaryCovPath;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
export async function getOSSFuzzCloudURL(projectName: string) {
|
| 64 |
+
const currentDate = new Date();
|
| 65 |
+
const yesterday = new Date(currentDate);
|
| 66 |
+
yesterday.setDate(yesterday.getDate() - 1);
|
| 67 |
+
|
| 68 |
+
const day = yesterday.getDate();
|
| 69 |
+
const month = yesterday.getMonth();
|
| 70 |
+
const year = yesterday.getFullYear();
|
| 71 |
+
|
| 72 |
+
let urlString =
|
| 73 |
+
'https://storage.googleapis.com/oss-fuzz-coverage/' +
|
| 74 |
+
projectName +
|
| 75 |
+
'/reports/' +
|
| 76 |
+
year.toString();
|
| 77 |
+
|
| 78 |
+
if (month < 10) {
|
| 79 |
+
urlString += '0';
|
| 80 |
+
}
|
| 81 |
+
urlString += month.toString();
|
| 82 |
+
if (day < 10) {
|
| 83 |
+
urlString += '0';
|
| 84 |
+
}
|
| 85 |
+
urlString += day.toString();
|
| 86 |
+
|
| 87 |
+
return urlString;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Checks if the current workspace has a generated OSS-Fuzz folder. This is the
|
| 92 |
+
* generated folder from our auto-generation capabilities.
|
| 93 |
+
*
|
| 94 |
+
* @returns boolean
|
| 95 |
+
*/
|
| 96 |
+
export async function hasOssFuzzInWorkspace() {
|
| 97 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 98 |
+
|
| 99 |
+
if (!workspaceFolder) {
|
| 100 |
+
return false;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Identify if the workspace folder has a OSS-Fuzz set up.
|
| 104 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 105 |
+
const ossfuzzDockerFilepath = vscode.Uri.file(wsPath + '/OSS-Fuzz/');
|
| 106 |
+
try {
|
| 107 |
+
if (await vscode.workspace.fs.readDirectory(ossfuzzDockerFilepath)) {
|
| 108 |
+
for (const [name, type] of await vscode.workspace.fs.readDirectory(
|
| 109 |
+
ossfuzzDockerFilepath
|
| 110 |
+
)) {
|
| 111 |
+
// If it's a directory then we know we have the project set up in there.
|
| 112 |
+
if (type === 2) {
|
| 113 |
+
// We assume this is the project folder for now.
|
| 114 |
+
println('Found the relevant directory: ' + name);
|
| 115 |
+
return true;
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
} catch {
|
| 120 |
+
/* empty */
|
| 121 |
+
}
|
| 122 |
+
return false;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/**
|
| 126 |
+
* Gets the project name of the integrated OSS-Fuzz project.
|
| 127 |
+
* @returns string
|
| 128 |
+
*/
|
| 129 |
+
export async function getOssFuzzWorkspaceProjectName() {
|
| 130 |
+
const workspaceFolder = vscode.workspace.workspaceFolders;
|
| 131 |
+
if (!workspaceFolder) {
|
| 132 |
+
return 'N/A';
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// Identify if the workspace folder has a OSS-Fuzz set up.
|
| 136 |
+
const wsPath = workspaceFolder[0].uri.fsPath; // gets the path of the first workspace folder
|
| 137 |
+
const ossfuzzDockerFilepath = vscode.Uri.file(wsPath + '/OSS-Fuzz/');
|
| 138 |
+
try {
|
| 139 |
+
if (await vscode.workspace.fs.readDirectory(ossfuzzDockerFilepath)) {
|
| 140 |
+
for (const [name, type] of await vscode.workspace.fs.readDirectory(
|
| 141 |
+
ossfuzzDockerFilepath
|
| 142 |
+
)) {
|
| 143 |
+
if (type === 2) {
|
| 144 |
+
// println('Is a directory');
|
| 145 |
+
// We assume this is the project folder for now.
|
| 146 |
+
return name;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
} catch {
|
| 151 |
+
/* empty */
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
return 'N/A';
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* Lists the fuzzers available in the OSS-Fuzz build project.
|
| 159 |
+
*
|
| 160 |
+
* @param projectName
|
| 161 |
+
* @param ossFuzzRepositoryPath
|
| 162 |
+
* @returns
|
| 163 |
+
*/
|
| 164 |
+
export async function listFuzzersForProject(
|
| 165 |
+
projectName: string,
|
| 166 |
+
ossFuzzRepositoryPath: string
|
| 167 |
+
) {
|
| 168 |
+
const projectOssFuzzBuildPath = vscode.Uri.file(
|
| 169 |
+
ossFuzzRepositoryPath + '/build/out/' + projectName
|
| 170 |
+
);
|
| 171 |
+
const fuzzersInProject: Array<string> = [];
|
| 172 |
+
for (const [name, type] of await vscode.workspace.fs.readDirectory(
|
| 173 |
+
projectOssFuzzBuildPath
|
| 174 |
+
)) {
|
| 175 |
+
// Is it a file?
|
| 176 |
+
if (type === 1) {
|
| 177 |
+
const filepath =
|
| 178 |
+
ossFuzzRepositoryPath + '/build/out/' + projectName + '/' + name;
|
| 179 |
+
const binary = fs.readFileSync(filepath);
|
| 180 |
+
|
| 181 |
+
// Check if fuzzer entrypoint exists in file. This is similar to how OSS-Fuzz
|
| 182 |
+
// checks whether a file is fuzzer or not.
|
| 183 |
+
if (binary.lastIndexOf('LLVMFuzzerTestOneInput') !== -1) {
|
| 184 |
+
fuzzersInProject.push(name);
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
println('Successfully build the project.');
|
| 189 |
+
println('The fuzzers in project');
|
| 190 |
+
for (const fuzzName of fuzzersInProject) {
|
| 191 |
+
println(fuzzName);
|
| 192 |
+
}
|
| 193 |
+
return fuzzersInProject;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* Helper functions for identifying the primary programming language of the workspace.
|
| 198 |
+
*
|
| 199 |
+
* This is achieved by identifying the suffix of files and then sorting
|
| 200 |
+
* based on those with most of a given language supported by OSS-Fuzz.
|
| 201 |
+
*
|
| 202 |
+
* @returns
|
| 203 |
+
*/
|
| 204 |
+
export async function determineWorkspaceLanguage() {
|
| 205 |
+
const pythonFiles = await vscode.workspace.findFiles('**/*.py');
|
| 206 |
+
const cppFiles = await vscode.workspace.findFiles('**/*.c++');
|
| 207 |
+
const cfiles = await vscode.workspace.findFiles('**/*.c');
|
| 208 |
+
const rustFiles = await vscode.workspace.findFiles('**/*.rust');
|
| 209 |
+
const golangFiles = await vscode.workspace.findFiles('**/*.go');
|
| 210 |
+
|
| 211 |
+
println('Number of python files: ' + pythonFiles.length);
|
| 212 |
+
println('Number of C++ files: ' + cppFiles.length);
|
| 213 |
+
println('Number of C files: ' + cfiles.length);
|
| 214 |
+
println('Number of rustFiles files: ' + rustFiles.length);
|
| 215 |
+
println('Number of golangFiles files: ' + golangFiles.length);
|
| 216 |
+
|
| 217 |
+
const maxCount = Math.max(
|
| 218 |
+
pythonFiles.length,
|
| 219 |
+
cppFiles.length,
|
| 220 |
+
cfiles.length,
|
| 221 |
+
rustFiles.length,
|
| 222 |
+
golangFiles.length
|
| 223 |
+
);
|
| 224 |
+
let target = '';
|
| 225 |
+
if (maxCount === pythonFiles.length) {
|
| 226 |
+
target = 'python';
|
| 227 |
+
} else if (maxCount === cppFiles.length) {
|
| 228 |
+
target = 'c++';
|
| 229 |
+
} else if (maxCount === cfiles.length) {
|
| 230 |
+
target = 'c';
|
| 231 |
+
} else if (maxCount === rustFiles.length) {
|
| 232 |
+
target = 'rust';
|
| 233 |
+
} else if (maxCount === golangFiles.length) {
|
| 234 |
+
target = 'golang';
|
| 235 |
+
} else {
|
| 236 |
+
target = 'not implemented';
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
println('Target language: ' + target);
|
| 240 |
+
return target;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
/**
|
| 244 |
+
* Helper method to execute commands on the system.
|
| 245 |
+
*/
|
| 246 |
+
export async function systemSync(cmd: string, args: Array<string | undefined>) {
|
| 247 |
+
debugPrintln('Running command');
|
| 248 |
+
debugPrintln(cmd);
|
| 249 |
+
debugPrintln(args.toString());
|
| 250 |
+
debugPrintln('<<<<<<<<<<<<');
|
| 251 |
+
|
| 252 |
+
// Launch the command
|
| 253 |
+
const command = spawn(cmd, args);
|
| 254 |
+
|
| 255 |
+
// Callbacks for output events, to capture stdout and stderr live.
|
| 256 |
+
command.stdout.on('data', (x: {toString: () => string}) => {
|
| 257 |
+
printRaw(x.toString());
|
| 258 |
+
});
|
| 259 |
+
command.stderr.on('data', (x: {toString: () => string}) => {
|
| 260 |
+
printRaw(x.toString());
|
| 261 |
+
});
|
| 262 |
+
|
| 263 |
+
// Monitor for child exit.
|
| 264 |
+
let hasChildExited = 0;
|
| 265 |
+
let childExitCode = 0;
|
| 266 |
+
command.on('exit', (code: any, signal: any) => {
|
| 267 |
+
// println('child process exited with ' + `code ${code} and signal ${signal}`);
|
| 268 |
+
childExitCode = code;
|
| 269 |
+
hasChildExited = 1;
|
| 270 |
+
});
|
| 271 |
+
|
| 272 |
+
// Block until the child process has exited.
|
| 273 |
+
const snooze = (ms: number) =>
|
| 274 |
+
new Promise(resolve => setTimeout(resolve, ms));
|
| 275 |
+
|
| 276 |
+
let idx = 0;
|
| 277 |
+
const maxSeconds = 1800;
|
| 278 |
+
debugPrintln('Child exited: ' + hasChildExited);
|
| 279 |
+
|
| 280 |
+
// I think we can convert the following loop to a Promise wrapping the command
|
| 281 |
+
// exeuction. TODO(David).
|
| 282 |
+
while (hasChildExited === 0 && idx < maxSeconds) {
|
| 283 |
+
idx += 1;
|
| 284 |
+
await snooze(1000);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// Command execution is done, return appropriately if success/error.
|
| 288 |
+
if (childExitCode !== 0) {
|
| 289 |
+
println('Command execution errored');
|
| 290 |
+
return [false, command.toString()];
|
| 291 |
+
}
|
| 292 |
+
// println('Succes');
|
| 293 |
+
return [true, command.toString()];
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
export async function systemSyncLogIfFailure(
|
| 297 |
+
cmd: string,
|
| 298 |
+
args: Array<string | undefined>
|
| 299 |
+
): Promise<boolean> {
|
| 300 |
+
const [res, cmdMsg] = await systemSync(cmd, args);
|
| 301 |
+
if (res === false) {
|
| 302 |
+
println(cmdMsg);
|
| 303 |
+
return false;
|
| 304 |
+
}
|
| 305 |
+
return true;
|
| 306 |
+
}
|