Add files using upload-large-folder tool
Browse files- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder-javascript/Dockerfile +20 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder-jvm/Dockerfile +68 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder-ruby/ruzzy-build +28 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/Dockerfile +213 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/README.md +83 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bazel.bazelrc +20 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bazel_build_fuzz_tests +90 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bisect_clang.py +227 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bisect_clang_test.py +294 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/cargo +55 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile +420 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_afl +53 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_honggfuzz +33 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_javascript_fuzzer +37 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_libfuzzer +25 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_python_fuzzer +128 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/detect_repo.py +182 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/detect_repo_test.py +121 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_deps.sh +44 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_java.sh +31 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_javascript.sh +27 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_python.sh +23 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_swift.sh +67 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/cpp.cc +18 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/llvmsymbol.diff +50 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/ossfuzz_coverage_runner.go +69 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/precompile_centipede +49 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/precompile_honggfuzz +45 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/.gitignore +4 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/redos.py +84 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/setup.py +21 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/README.md +1 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/eval_command_injection.py +52 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/ansible-runner-cve-2021-4041/fuzz_ansible_runner.py +64 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/libvcs-cve-2022-21187/build.sh +21 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/libvcs-cve-2022-21187/fuzz_libvcs.py +45 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/python-ldap-GHSL-2021-117/build.sh +25 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/build.sh +22 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/fuzz_pytorch_lightning.dict +1 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/yaml_deserialization_general.py +47 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/yaml_deserialization_simple.py +54 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/srcmap +66 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/test_data/culprit-commit.txt +30 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/write_labels.py +40 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-clang/Dockerfile +79 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/bad_build_check +494 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/convertcorpus/go.mod +10 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/gocovmerge/LICENSE +22 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/gocovsum/gocovsum.go +171 -0
- local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/pprof-merge/main.go +68 -0
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder-javascript/Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 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 |
+
ARG IMG_TAG=latest
|
| 18 |
+
FROM ghcr.io/aixcc-finals/base-builder:${IMG_TAG}
|
| 19 |
+
|
| 20 |
+
RUN install_javascript.sh
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder-jvm/Dockerfile
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#
|
| 15 |
+
################################################################################
|
| 16 |
+
|
| 17 |
+
ARG IMG_TAG=latest
|
| 18 |
+
FROM ghcr.io/aixcc-finals/base-builder:${IMG_TAG} AS base
|
| 19 |
+
|
| 20 |
+
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
|
| 21 |
+
ENV JAVA_15_HOME /usr/lib/jvm/java-15-openjdk-amd64
|
| 22 |
+
ENV JVM_LD_LIBRARY_PATH $JAVA_HOME/lib/server
|
| 23 |
+
ENV PATH $PATH:$JAVA_HOME/bin
|
| 24 |
+
ENV JAZZER_API_PATH "/usr/local/lib/jazzer_api_deploy.jar"
|
| 25 |
+
ENV JAZZER_JUNIT_PATH "/usr/local/bin/jazzer_junit.jar"
|
| 26 |
+
|
| 27 |
+
RUN install_java.sh
|
| 28 |
+
|
| 29 |
+
RUN chmod 777 /usr/local/bin && chmod 777 /usr/local/lib
|
| 30 |
+
|
| 31 |
+
FROM base AS builder
|
| 32 |
+
RUN useradd -m jazzer_user
|
| 33 |
+
|
| 34 |
+
USER jazzer_user
|
| 35 |
+
|
| 36 |
+
WORKDIR $SRC
|
| 37 |
+
|
| 38 |
+
RUN git clone https://github.com/aixcc-finals/jazzer-aixcc jazzer && \
|
| 39 |
+
cd jazzer && \
|
| 40 |
+
git checkout 43791565a765b854b537d878c9cab757ff1f2140
|
| 41 |
+
|
| 42 |
+
WORKDIR $SRC/jazzer
|
| 43 |
+
|
| 44 |
+
RUN echo "build --java_runtime_version=local_jdk_17" >> .bazelrc \
|
| 45 |
+
&& echo "build --cxxopt=-stdlib=libc++" >> .bazelrc \
|
| 46 |
+
&& echo "build --linkopt=-lc++" >> .bazelrc
|
| 47 |
+
|
| 48 |
+
RUN bazel build \
|
| 49 |
+
//src/main/java/com/code_intelligence/jazzer:jazzer_standalone_deploy.jar \
|
| 50 |
+
//deploy:jazzer-api \
|
| 51 |
+
//deploy:jazzer-junit \
|
| 52 |
+
//launcher:jazzer
|
| 53 |
+
|
| 54 |
+
RUN cp $(bazel cquery --output=files //src/main/java/com/code_intelligence/jazzer:jazzer_standalone_deploy.jar) /usr/local/bin/jazzer_agent_deploy.jar && \
|
| 55 |
+
cp $(bazel cquery --output=files //launcher:jazzer) /usr/local/bin/jazzer_driver && \
|
| 56 |
+
cp $(bazel cquery --output=files //deploy:jazzer-api) $JAZZER_API_PATH && \
|
| 57 |
+
cp $(bazel cquery --output=files //deploy:jazzer-junit) $JAZZER_JUNIT_PATH
|
| 58 |
+
|
| 59 |
+
FROM base AS final
|
| 60 |
+
|
| 61 |
+
COPY --from=builder /usr/local/bin/jazzer_agent_deploy.jar /usr/local/bin/jazzer_agent_deploy.jar
|
| 62 |
+
COPY --from=builder /usr/local/bin/jazzer_driver /usr/local/bin/jazzer_driver
|
| 63 |
+
COPY --from=builder $JAZZER_API_PATH $JAZZER_API_PATH
|
| 64 |
+
COPY --from=builder $JAZZER_JUNIT_PATH $JAZZER_JUNIT_PATH
|
| 65 |
+
|
| 66 |
+
RUN chmod 755 /usr/local/bin && chmod 755 /usr/local/lib
|
| 67 |
+
|
| 68 |
+
WORKDIR $SRC
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder-ruby/ruzzy-build
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash -e
|
| 2 |
+
# Copyright 2024 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
fuzz_target=$(basename "$1")
|
| 19 |
+
echo "BASENAME: $fuzz_target ---"
|
| 20 |
+
harness_sh=${fuzz_target::-3}
|
| 21 |
+
|
| 22 |
+
cp $1 $OUT/$fuzz_target
|
| 23 |
+
|
| 24 |
+
echo """#!/usr/bin/env bash
|
| 25 |
+
|
| 26 |
+
ruzzy $fuzz_target
|
| 27 |
+
""" > $OUT/$harness_sh
|
| 28 |
+
chmod +x $OUT/$harness_sh
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/Dockerfile
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
#
|
| 15 |
+
################################################################################
|
| 16 |
+
|
| 17 |
+
ARG IMG_TAG=latest
|
| 18 |
+
FROM ghcr.io/aixcc-finals/base-clang:${IMG_TAG}
|
| 19 |
+
|
| 20 |
+
COPY install_deps.sh /
|
| 21 |
+
RUN /install_deps.sh && rm /install_deps.sh
|
| 22 |
+
|
| 23 |
+
# Build and install latest Python 3.10.
|
| 24 |
+
ENV PYTHON_VERSION 3.10.14
|
| 25 |
+
RUN PYTHON_DEPS="\
|
| 26 |
+
zlib1g-dev \
|
| 27 |
+
libncurses5-dev \
|
| 28 |
+
libgdbm-dev \
|
| 29 |
+
libnss3-dev \
|
| 30 |
+
libssl-dev \
|
| 31 |
+
libsqlite3-dev \
|
| 32 |
+
libreadline-dev \
|
| 33 |
+
libffi-dev \
|
| 34 |
+
libbz2-dev \
|
| 35 |
+
liblzma-dev" && \
|
| 36 |
+
unset CFLAGS CXXFLAGS && \
|
| 37 |
+
apt-get install -y $PYTHON_DEPS && \
|
| 38 |
+
cd /tmp && \
|
| 39 |
+
curl -O https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.xz && \
|
| 40 |
+
tar -xvf Python-$PYTHON_VERSION.tar.xz && \
|
| 41 |
+
cd Python-$PYTHON_VERSION && \
|
| 42 |
+
./configure --enable-optimizations --enable-shared && \
|
| 43 |
+
make -j$(nproc) install && \
|
| 44 |
+
ldconfig && \
|
| 45 |
+
ln -s /usr/local/bin/python3 /usr/local/bin/python && \
|
| 46 |
+
cd .. && \
|
| 47 |
+
rm -r /tmp/Python-$PYTHON_VERSION.tar.xz /tmp/Python-$PYTHON_VERSION && \
|
| 48 |
+
rm -rf /usr/local/lib/python${PYTHON_VERSION%.*}/test && \
|
| 49 |
+
python3 -m ensurepip && \
|
| 50 |
+
python3 -m pip install --upgrade pip && \
|
| 51 |
+
apt-get remove -y $PYTHON_DEPS # https://github.com/google/oss-fuzz/issues/3888
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
ENV CCACHE_VERSION 4.10.2
|
| 55 |
+
RUN cd /tmp && curl -OL https://github.com/ccache/ccache/releases/download/v$CCACHE_VERSION/ccache-$CCACHE_VERSION.tar.xz && \
|
| 56 |
+
tar -xvf ccache-$CCACHE_VERSION.tar.xz && cd ccache-$CCACHE_VERSION && \
|
| 57 |
+
mkdir build && cd build && \
|
| 58 |
+
export LDFLAGS='-lpthread' && \
|
| 59 |
+
cmake -D CMAKE_BUILD_TYPE=Release .. && \
|
| 60 |
+
make -j && make install && \
|
| 61 |
+
rm -rf /tmp/ccache-$CCACHE_VERSION /tmp/ccache-$CCACHE_VERSION.tar.xz
|
| 62 |
+
|
| 63 |
+
# Install six for Bazel rules.
|
| 64 |
+
RUN unset CFLAGS CXXFLAGS && pip3 install -v --no-cache-dir \
|
| 65 |
+
six==1.15.0 && rm -rf /tmp/*
|
| 66 |
+
|
| 67 |
+
# Install Bazel through Bazelisk, which automatically fetches the latest Bazel version.
|
| 68 |
+
ENV BAZELISK_VERSION 1.9.0
|
| 69 |
+
RUN curl -L https://github.com/bazelbuild/bazelisk/releases/download/v$BAZELISK_VERSION/bazelisk-linux-amd64 -o /usr/local/bin/bazel && \
|
| 70 |
+
chmod +x /usr/local/bin/bazel
|
| 71 |
+
|
| 72 |
+
# Default build flags for various sanitizers.
|
| 73 |
+
ENV SANITIZER_FLAGS_address "-fsanitize=address -fsanitize-address-use-after-scope"
|
| 74 |
+
ENV SANITIZER_FLAGS_hwaddress "-fsanitize=hwaddress -fuse-ld=lld -Wno-unused-command-line-argument"
|
| 75 |
+
|
| 76 |
+
# Set of '-fsanitize' flags matches '-fno-sanitize-recover' + 'unsigned-integer-overflow'.
|
| 77 |
+
ENV SANITIZER_FLAGS_undefined "-fsanitize=array-bounds,bool,builtin,enum,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
|
| 78 |
+
|
| 79 |
+
# Don't include "function" since it is unsupported on aarch64.
|
| 80 |
+
ENV SANITIZER_FLAGS_undefined_aarch64 "-fsanitize=array-bounds,bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
|
| 81 |
+
|
| 82 |
+
ENV SANITIZER_FLAGS_memory "-fsanitize=memory -fsanitize-memory-track-origins"
|
| 83 |
+
|
| 84 |
+
ENV SANITIZER_FLAGS_thread "-fsanitize=thread"
|
| 85 |
+
|
| 86 |
+
ENV SANITIZER_FLAGS_introspector "-O0 -flto -fno-inline-functions -fuse-ld=gold -Wno-unused-command-line-argument"
|
| 87 |
+
|
| 88 |
+
# Do not use any sanitizers in the coverage build.
|
| 89 |
+
ENV SANITIZER_FLAGS_coverage ""
|
| 90 |
+
|
| 91 |
+
# We use unsigned-integer-overflow as an additional coverage signal and have to
|
| 92 |
+
# suppress error messages. See https://github.com/google/oss-fuzz/issues/910.
|
| 93 |
+
ENV UBSAN_OPTIONS="silence_unsigned_overflow=1"
|
| 94 |
+
|
| 95 |
+
# To suppress warnings from binaries running during compilation.
|
| 96 |
+
ENV DFSAN_OPTIONS='warn_unimplemented=0'
|
| 97 |
+
|
| 98 |
+
# Default build flags for coverage feedback.
|
| 99 |
+
ENV COVERAGE_FLAGS="-fsanitize=fuzzer-no-link"
|
| 100 |
+
|
| 101 |
+
# Use '-Wno-unused-command-line-argument' to suppress "warning: -ldl: 'linker' input unused"
|
| 102 |
+
# messages which are treated as errors by some projects.
|
| 103 |
+
ENV COVERAGE_FLAGS_coverage "-fprofile-instr-generate -fcoverage-mapping -pthread -Wl,--no-as-needed -Wl,-ldl -Wl,-lm -Wno-unused-command-line-argument"
|
| 104 |
+
|
| 105 |
+
# Default sanitizer, fuzzing engine and architecture to use.
|
| 106 |
+
ENV SANITIZER="address"
|
| 107 |
+
ENV FUZZING_ENGINE="libfuzzer"
|
| 108 |
+
ENV ARCHITECTURE="x86_64"
|
| 109 |
+
|
| 110 |
+
# DEPRECATED - NEW CODE SHOULD NOT USE THIS. OLD CODE SHOULD STOP. Please use
|
| 111 |
+
# LIB_FUZZING_ENGINE instead.
|
| 112 |
+
# Path to fuzzing engine library to support some old users of
|
| 113 |
+
# LIB_FUZZING_ENGINE.
|
| 114 |
+
ENV LIB_FUZZING_ENGINE_DEPRECATED="/usr/lib/libFuzzingEngine.a"
|
| 115 |
+
|
| 116 |
+
# Argument passed to compiler to link against fuzzing engine.
|
| 117 |
+
# Defaults to the path, but is "-fsanitize=fuzzer" in libFuzzer builds.
|
| 118 |
+
ENV LIB_FUZZING_ENGINE="/usr/lib/libFuzzingEngine.a"
|
| 119 |
+
|
| 120 |
+
# TODO: remove after tpm2 catchup.
|
| 121 |
+
ENV FUZZER_LDFLAGS ""
|
| 122 |
+
|
| 123 |
+
WORKDIR $SRC
|
| 124 |
+
|
| 125 |
+
RUN git clone https://github.com/AFLplusplus/AFLplusplus.git aflplusplus && \
|
| 126 |
+
cd aflplusplus && \
|
| 127 |
+
git checkout daaefcddc063b356018c29027494a00bcfc3e240 && \
|
| 128 |
+
wget --no-check-certificate -O oss.sh https://raw.githubusercontent.com/vanhauser-thc/binary_blobs/master/oss.sh && \
|
| 129 |
+
rm -rf .git && \
|
| 130 |
+
chmod 755 oss.sh
|
| 131 |
+
|
| 132 |
+
# Do precompiles before copying other scripts for better cache efficiency.
|
| 133 |
+
COPY precompile_afl /usr/local/bin/
|
| 134 |
+
RUN precompile_afl
|
| 135 |
+
|
| 136 |
+
RUN cd $SRC && \
|
| 137 |
+
curl -L -O https://github.com/google/honggfuzz/archive/oss-fuzz.tar.gz && \
|
| 138 |
+
mkdir honggfuzz && \
|
| 139 |
+
cd honggfuzz && \
|
| 140 |
+
tar -xz --strip-components=1 -f $SRC/oss-fuzz.tar.gz && \
|
| 141 |
+
rm -rf examples $SRC/oss-fuzz.tar.gz
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
COPY precompile_honggfuzz /usr/local/bin/
|
| 145 |
+
RUN precompile_honggfuzz
|
| 146 |
+
|
| 147 |
+
RUN cd $SRC && \
|
| 148 |
+
git clone https://github.com/google/fuzztest && \
|
| 149 |
+
cd fuzztest && \
|
| 150 |
+
git checkout a37d133f714395cabc20dd930969a889495c9f53 && \
|
| 151 |
+
rm -rf .git
|
| 152 |
+
|
| 153 |
+
ENV CENTIPEDE_BIN_DIR=$SRC/fuzztest/bazel-bin
|
| 154 |
+
COPY precompile_centipede /usr/local/bin/
|
| 155 |
+
RUN precompile_centipede
|
| 156 |
+
|
| 157 |
+
COPY sanitizers /usr/local/lib/sanitizers
|
| 158 |
+
|
| 159 |
+
COPY bazel_build_fuzz_tests \
|
| 160 |
+
cargo \
|
| 161 |
+
compile \
|
| 162 |
+
compile_afl \
|
| 163 |
+
compile_centipede \
|
| 164 |
+
compile_honggfuzz \
|
| 165 |
+
compile_fuzztests.sh \
|
| 166 |
+
compile_go_fuzzer \
|
| 167 |
+
compile_javascript_fuzzer \
|
| 168 |
+
compile_libfuzzer \
|
| 169 |
+
compile_native_go_fuzzer \
|
| 170 |
+
compile_python_fuzzer \
|
| 171 |
+
debug_afl \
|
| 172 |
+
# Go, JavaScript, Java, Python, Rust, and Swift installation scripts.
|
| 173 |
+
install_go.sh \
|
| 174 |
+
install_javascript.sh \
|
| 175 |
+
install_java.sh \
|
| 176 |
+
install_python.sh \
|
| 177 |
+
install_ruby.sh \
|
| 178 |
+
install_rust.sh \
|
| 179 |
+
install_swift.sh \
|
| 180 |
+
python_coverage_helper.py \
|
| 181 |
+
bash_parser.py \
|
| 182 |
+
srcmap \
|
| 183 |
+
write_labels.py \
|
| 184 |
+
/usr/local/bin/
|
| 185 |
+
|
| 186 |
+
# TODO: Build this as part of a multi-stage build.
|
| 187 |
+
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang-jcc /usr/local/bin/
|
| 188 |
+
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang++-jcc /usr/local/bin
|
| 189 |
+
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang-jcc2 /usr/local/bin/
|
| 190 |
+
ADD https://commondatastorage.googleapis.com/clusterfuzz-builds/jcc/clang++-jcc2 /usr/local/bin
|
| 191 |
+
RUN chmod +x /usr/local/bin/clang-jcc /usr/local/bin/clang++-jcc /usr/local/bin/clang-jcc2 /usr/local/bin/clang++-jcc2
|
| 192 |
+
|
| 193 |
+
COPY llvmsymbol.diff $SRC
|
| 194 |
+
COPY detect_repo.py /opt/cifuzz/
|
| 195 |
+
COPY bazel.bazelrc /root/.bazelrc
|
| 196 |
+
|
| 197 |
+
# Set up ccache binary and cache directory.
|
| 198 |
+
# /ccache/bin will contain the compiler wrappers, and /ccache/cache will
|
| 199 |
+
# contain the actual cache, which can be saved.
|
| 200 |
+
# To use this, set PATH=/ccache/bin:$PATH.
|
| 201 |
+
RUN mkdir -p /ccache/bin && mkdir -p /ccache/cache && \
|
| 202 |
+
ln -s /usr/local/bin/ccache /ccache/bin/clang && \
|
| 203 |
+
ln -s /usr/local/bin/ccache /ccache/bin/clang++ && \
|
| 204 |
+
ln -s /usr/local/bin/ccache /ccache/bin/clang-jcc && \
|
| 205 |
+
ln -s /usr/local/bin/ccache /ccache/bin/clang++-jcc
|
| 206 |
+
ENV CCACHE_DIR /ccache/cache
|
| 207 |
+
|
| 208 |
+
# Don't check that the compiler is the same, so we can switch between jcc and
|
| 209 |
+
# clang under the hood and re-use the same build cache.
|
| 210 |
+
ENV CCACHE_COMPILERCHECK none
|
| 211 |
+
ENV CCACHE_COMPILERTYPE clang
|
| 212 |
+
|
| 213 |
+
CMD ["compile"]
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# base-builder
|
| 2 |
+
> Abstract base image for project builders.
|
| 3 |
+
|
| 4 |
+
Every project image supports multiple commands that can be invoked through docker after the image is built:
|
| 5 |
+
|
| 6 |
+
<pre>
|
| 7 |
+
docker run --rm -ti gcr.io/oss-fuzz/<b><i>$project</i></b> <i><command></i> <i><arguments...></i>
|
| 8 |
+
</pre>
|
| 9 |
+
|
| 10 |
+
# Supported Commands
|
| 11 |
+
|
| 12 |
+
| Command | Description |
|
| 13 |
+
|---------|-------------|
|
| 14 |
+
| `compile` (default) | build all fuzz targets
|
| 15 |
+
| `/bin/bash` | drop into shell, execute `compile` script to start build.
|
| 16 |
+
|
| 17 |
+
# Build Configuration
|
| 18 |
+
|
| 19 |
+
A single build image can build same set of fuzzers in many configurations.
|
| 20 |
+
The configuration is picked through one or more environment variables.
|
| 21 |
+
|
| 22 |
+
| Env Variable | Description
|
| 23 |
+
| ------------- | --------
|
| 24 |
+
| `$SANITIZER ("address")` | Specifies predefined sanitizer configuration to use. `address` or `memory` or `undefined`.
|
| 25 |
+
| `$SANITIZER_FLAGS` | Specify compiler sanitizer flags directly. Overrides `$SANITIZER`.
|
| 26 |
+
| `$COVERAGE_FLAGS` | Specify compiler flags to use for fuzzer feedback coverage.
|
| 27 |
+
| `$BUILD_UID` | User id to use while building fuzzers.
|
| 28 |
+
|
| 29 |
+
## Examples
|
| 30 |
+
|
| 31 |
+
- *building sqlite3 fuzzer with UBSan (`SANITIZER=undefined`):*
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
<pre>
|
| 35 |
+
docker run --rm -ti -e <i>SANITIZER</i>=<i>undefined</i> gcr.io/oss-fuzz/sqlite3
|
| 36 |
+
</pre>
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Image Files Layout
|
| 40 |
+
|
| 41 |
+
| Location|Env| Description |
|
| 42 |
+
|---------| -------- | ---------- |
|
| 43 |
+
| `/out/` | `$OUT` | Directory to store build artifacts (fuzz targets, dictionaries, options files, seed corpus archives). |
|
| 44 |
+
| `/src/` | `$SRC` | Directory to checkout source files |
|
| 45 |
+
| `/work/`| `$WORK` | Directory for storing intermediate files |
|
| 46 |
+
| `/usr/lib/libFuzzingEngine.a` | `$LIB_FUZZING_ENGINE` | Location of prebuilt fuzzing engine library (e.g. libFuzzer) that needs to be linked with all fuzz targets.
|
| 47 |
+
|
| 48 |
+
While files layout is fixed within a container, the environment variables are
|
| 49 |
+
provided to be able to write retargetable scripts.
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
## Compiler Flags
|
| 53 |
+
|
| 54 |
+
You *must* use special compiler flags to build your project and fuzz targets.
|
| 55 |
+
These flags are provided in following environment variables:
|
| 56 |
+
|
| 57 |
+
| Env Variable | Description
|
| 58 |
+
| ------------- | --------
|
| 59 |
+
| `$CC` | The C compiler binary.
|
| 60 |
+
| `$CXX`, `$CCC` | The C++ compiler binary.
|
| 61 |
+
| `$CFLAGS` | C compiler flags.
|
| 62 |
+
| `$CXXFLAGS` | C++ compiler flags.
|
| 63 |
+
|
| 64 |
+
Most well-crafted build scripts will automatically use these variables. If not,
|
| 65 |
+
pass them manually to the build tool.
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# Child Image Interface
|
| 69 |
+
|
| 70 |
+
## Sources
|
| 71 |
+
|
| 72 |
+
Child image has to checkout all sources that it needs to compile fuzz targets into
|
| 73 |
+
`$SRC` directory. When the image is executed, a directory could be mounted on top
|
| 74 |
+
of these with local checkouts using
|
| 75 |
+
`docker run -v $HOME/my_project:/src/my_project ...`.
|
| 76 |
+
|
| 77 |
+
## Other Required Files
|
| 78 |
+
|
| 79 |
+
Following files have to be added by child images:
|
| 80 |
+
|
| 81 |
+
| File Location | Description |
|
| 82 |
+
| ------------- | ----------- |
|
| 83 |
+
| `$SRC/build.sh` | build script to build the project and its fuzz targets |
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bazel.bazelrc
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 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 |
+
# Pass variables from environment.
|
| 19 |
+
build --action_env=FUZZ_INTROSPECTOR
|
| 20 |
+
build --action_env=FUZZINTRO_OUTDIR
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bazel_build_fuzz_tests
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2021 Google LLC
|
| 4 |
+
#
|
| 5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
# you may not use this file except in compliance with the License.
|
| 7 |
+
# You may obtain a copy of the License at
|
| 8 |
+
#
|
| 9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
#
|
| 11 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
# See the License for the specific language governing permissions and
|
| 15 |
+
# limitations under the License.
|
| 16 |
+
#
|
| 17 |
+
################################################################################
|
| 18 |
+
|
| 19 |
+
: "${BAZEL_FUZZ_TEST_TAG:=fuzz-test}"
|
| 20 |
+
: "${BAZEL_FUZZ_TEST_EXCLUDE_TAG:=no-oss-fuzz}"
|
| 21 |
+
: "${BAZEL_PACKAGE_SUFFIX:=_oss_fuzz}"
|
| 22 |
+
: "${BAZEL_TOOL:=bazel}"
|
| 23 |
+
: "${BAZEL_EXTRA_BUILD_FLAGS:=}"
|
| 24 |
+
|
| 25 |
+
if [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 26 |
+
BAZEL_LANGUAGE=java
|
| 27 |
+
else
|
| 28 |
+
BAZEL_LANGUAGE=cc
|
| 29 |
+
fi
|
| 30 |
+
|
| 31 |
+
if [[ -z "${BAZEL_FUZZ_TEST_QUERY:-}" ]]; then
|
| 32 |
+
BAZEL_FUZZ_TEST_QUERY="
|
| 33 |
+
let all_fuzz_tests = attr(tags, \"${BAZEL_FUZZ_TEST_TAG}\", \"//...\") in
|
| 34 |
+
let lang_fuzz_tests = attr(generator_function, \"^${BAZEL_LANGUAGE}_fuzz_test\$\", \$all_fuzz_tests) in
|
| 35 |
+
\$lang_fuzz_tests - attr(tags, \"${BAZEL_FUZZ_TEST_EXCLUDE_TAG}\", \$lang_fuzz_tests)
|
| 36 |
+
"
|
| 37 |
+
fi
|
| 38 |
+
|
| 39 |
+
echo "Using Bazel query to find fuzz targets: ${BAZEL_FUZZ_TEST_QUERY}"
|
| 40 |
+
|
| 41 |
+
declare -r OSS_FUZZ_TESTS=(
|
| 42 |
+
$(bazel query "${BAZEL_FUZZ_TEST_QUERY}" | sed "s/$/${BAZEL_PACKAGE_SUFFIX}/")
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
echo "Found ${#OSS_FUZZ_TESTS[@]} fuzz test packages:"
|
| 46 |
+
for oss_fuzz_test in "${OSS_FUZZ_TESTS[@]}"; do
|
| 47 |
+
echo " ${oss_fuzz_test}"
|
| 48 |
+
done
|
| 49 |
+
|
| 50 |
+
declare -r BAZEL_BUILD_FLAGS=(
|
| 51 |
+
"--@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing_oss_fuzz//:oss_fuzz_engine" \
|
| 52 |
+
"--@rules_fuzzing//fuzzing:java_engine=@rules_fuzzing_oss_fuzz//:oss_fuzz_java_engine" \
|
| 53 |
+
"--@rules_fuzzing//fuzzing:cc_engine_instrumentation=oss-fuzz" \
|
| 54 |
+
"--@rules_fuzzing//fuzzing:cc_engine_sanitizer=none" \
|
| 55 |
+
"--cxxopt=-stdlib=libc++" \
|
| 56 |
+
"--linkopt=-lc++" \
|
| 57 |
+
"--verbose_failures" \
|
| 58 |
+
"--spawn_strategy=standalone" \
|
| 59 |
+
"--action_env=CC=${CC}" "--action_env=CXX=${CXX}" \
|
| 60 |
+
${BAZEL_EXTRA_BUILD_FLAGS[*]}
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
echo "Building the fuzz tests with the following Bazel options:"
|
| 64 |
+
echo " ${BAZEL_BUILD_FLAGS[@]}"
|
| 65 |
+
|
| 66 |
+
${BAZEL_TOOL} build "${BAZEL_BUILD_FLAGS[@]}" "${OSS_FUZZ_TESTS[@]}"
|
| 67 |
+
|
| 68 |
+
echo "Extracting the fuzz test packages in the output directory."
|
| 69 |
+
for oss_fuzz_archive in $(find bazel-bin/ -name "*${BAZEL_PACKAGE_SUFFIX}.tar"); do
|
| 70 |
+
tar --no-same-owner -xvf "${oss_fuzz_archive}" -C "${OUT}"
|
| 71 |
+
done
|
| 72 |
+
|
| 73 |
+
if [ "$SANITIZER" = "coverage" ]; then
|
| 74 |
+
echo "Collecting the repository source files for coverage tracking."
|
| 75 |
+
declare -r COVERAGE_SOURCES="${OUT}/proc/self/cwd"
|
| 76 |
+
mkdir -p "${COVERAGE_SOURCES}"
|
| 77 |
+
declare -r RSYNC_FILTER_ARGS=(
|
| 78 |
+
"--include" "*.h"
|
| 79 |
+
"--include" "*.cc"
|
| 80 |
+
"--include" "*.hpp"
|
| 81 |
+
"--include" "*.cpp"
|
| 82 |
+
"--include" "*.c"
|
| 83 |
+
"--include" "*.inc"
|
| 84 |
+
"--include" "*/"
|
| 85 |
+
"--exclude" "*"
|
| 86 |
+
)
|
| 87 |
+
rsync -avLk "${RSYNC_FILTER_ARGS[@]}" \
|
| 88 |
+
"$(bazel info execution_root)/" \
|
| 89 |
+
"${COVERAGE_SOURCES}/"
|
| 90 |
+
fi
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bisect_clang.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 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 |
+
"""Use git bisect to find the Clang/LLVM commit causing a regression."""
|
| 18 |
+
|
| 19 |
+
import logging
|
| 20 |
+
import os
|
| 21 |
+
import re
|
| 22 |
+
import shutil
|
| 23 |
+
import subprocess
|
| 24 |
+
import sys
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def execute(command, *args, expect_zero=True, **kwargs):
|
| 28 |
+
"""Execute |command| and return the returncode, stdout and stderr."""
|
| 29 |
+
kwargs['stdout'] = subprocess.PIPE
|
| 30 |
+
kwargs['stderr'] = subprocess.PIPE
|
| 31 |
+
logging.debug('Running command: "%s"', str(command))
|
| 32 |
+
process = subprocess.Popen(command, *args, **kwargs)
|
| 33 |
+
stdout, stderr = process.communicate()
|
| 34 |
+
stdout = stdout.decode('utf-8')
|
| 35 |
+
stderr = stderr.decode('utf-8')
|
| 36 |
+
retcode = process.returncode
|
| 37 |
+
logging.info('Command: "%s" returned: %d.\nStdout: %s.\nStderr: %s',
|
| 38 |
+
str(command), retcode, stdout, stderr)
|
| 39 |
+
if expect_zero and retcode != 0:
|
| 40 |
+
raise subprocess.CalledProcessError(retcode, command)
|
| 41 |
+
return retcode, stdout, stderr
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def search_bisect_output(output):
|
| 45 |
+
"""Search |output| for a message indicating the culprit commit has been
|
| 46 |
+
found."""
|
| 47 |
+
# TODO(metzman): Is it necessary to look for "good"?
|
| 48 |
+
culprit_regex = re.compile('([a-z0-9]{40}) is the first (good|bad) commit')
|
| 49 |
+
match = re.match(culprit_regex, output)
|
| 50 |
+
return match.group(1) if match is not None else None
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class GitRepo:
|
| 54 |
+
"""Class for executing commmands on a git repo."""
|
| 55 |
+
|
| 56 |
+
def __init__(self, repo_dir):
|
| 57 |
+
self.repo_dir = repo_dir
|
| 58 |
+
|
| 59 |
+
def do_command(self, git_subcommand):
|
| 60 |
+
"""Execute a |git_subcommand| (a list of strings)."""
|
| 61 |
+
command = ['git', '-C', self.repo_dir] + git_subcommand
|
| 62 |
+
return execute(command)
|
| 63 |
+
|
| 64 |
+
def test_commit(self, test_command):
|
| 65 |
+
"""Build LLVM at the currently checkedout commit, then run |test_command|.
|
| 66 |
+
If returncode is 0 run 'git bisect good' otherwise return 'git bisect bad'.
|
| 67 |
+
Return None if bisect didn't finish yet. Return the culprit commit if it
|
| 68 |
+
does."""
|
| 69 |
+
build_clang(self.repo_dir)
|
| 70 |
+
retcode, _, _ = execute(test_command, shell=True, expect_zero=False)
|
| 71 |
+
if retcode == 0:
|
| 72 |
+
retcode, stdout, _ = self.do_bisect_command('good')
|
| 73 |
+
else:
|
| 74 |
+
retcode, stdout, _ = self.do_bisect_command('bad')
|
| 75 |
+
return search_bisect_output(stdout)
|
| 76 |
+
|
| 77 |
+
def bisect(self, good_commit, bad_commit, test_command):
|
| 78 |
+
"""Do git bisect assuming |good_commit| is good, |bad_commit| is bad and
|
| 79 |
+
|test_command| is an oracle. Return the culprit commit."""
|
| 80 |
+
self.bisect_start(good_commit, bad_commit, test_command)
|
| 81 |
+
result = self.test_commit(test_command)
|
| 82 |
+
while result is None:
|
| 83 |
+
result = self.test_commit(test_command)
|
| 84 |
+
return result
|
| 85 |
+
|
| 86 |
+
def bisect_start(self, good_commit, bad_commit, test_command):
|
| 87 |
+
"""Start doing git bisect."""
|
| 88 |
+
self.do_bisect_command('start')
|
| 89 |
+
# Do bad commit first since it is more likely to be recent.
|
| 90 |
+
self.test_start_commit(bad_commit, 'bad', test_command)
|
| 91 |
+
self.test_start_commit(good_commit, 'good', test_command)
|
| 92 |
+
|
| 93 |
+
def do_bisect_command(self, subcommand):
|
| 94 |
+
"""Execute a git bisect |subcommand| (string) and return the result."""
|
| 95 |
+
return self.do_command(['bisect', subcommand])
|
| 96 |
+
|
| 97 |
+
def test_start_commit(self, commit, label, test_command):
|
| 98 |
+
"""Use |test_command| to test the first good or bad |commit| (depending on
|
| 99 |
+
|label|)."""
|
| 100 |
+
assert label in ('good', 'bad'), label
|
| 101 |
+
self.do_command(['checkout', commit])
|
| 102 |
+
build_clang(self.repo_dir)
|
| 103 |
+
retcode, _, _ = execute(test_command, shell=True, expect_zero=False)
|
| 104 |
+
if label == 'good' and retcode != 0:
|
| 105 |
+
raise BisectError('Test command "%s" returns %d on first good commit %s' %
|
| 106 |
+
(test_command, retcode, commit))
|
| 107 |
+
if label == 'bad' and retcode == 0:
|
| 108 |
+
raise BisectError('Test command "%s" returns %d on first bad commit %s' %
|
| 109 |
+
(test_command, retcode, commit))
|
| 110 |
+
|
| 111 |
+
self.do_bisect_command(label)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
class BisectError(Exception):
|
| 115 |
+
"""Error that was encountered during bisection."""
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def get_clang_build_env():
|
| 119 |
+
"""Get an environment for building Clang."""
|
| 120 |
+
env = os.environ.copy()
|
| 121 |
+
for variable in ['CXXFLAGS', 'CFLAGS']:
|
| 122 |
+
if variable in env:
|
| 123 |
+
del env[variable]
|
| 124 |
+
return env
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def install_clang_build_deps():
|
| 128 |
+
"""Instal dependencies necessary to build clang."""
|
| 129 |
+
execute([
|
| 130 |
+
'apt-get', 'install', '-y', 'build-essential', 'make', 'cmake',
|
| 131 |
+
'ninja-build', 'git', 'subversion', 'g++-multilib'
|
| 132 |
+
])
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def clone_with_retries(repo, local_path, num_retries=10):
|
| 136 |
+
"""Clone |repo| to |local_path| if it doesn't exist already. Try up to
|
| 137 |
+
|num_retries| times. Return False if unable to checkout."""
|
| 138 |
+
if os.path.isdir(local_path):
|
| 139 |
+
return
|
| 140 |
+
for _ in range(num_retries):
|
| 141 |
+
if os.path.isdir(local_path):
|
| 142 |
+
shutil.rmtree(local_path)
|
| 143 |
+
retcode, _, _ = execute(['git', 'clone', repo, local_path],
|
| 144 |
+
expect_zero=False)
|
| 145 |
+
if retcode == 0:
|
| 146 |
+
return
|
| 147 |
+
raise Exception('Could not checkout %s.' % repo)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def get_clang_target_arch():
|
| 151 |
+
"""Get target architecture we want clang to target when we build it."""
|
| 152 |
+
_, arch, _ = execute(['uname', '-m'])
|
| 153 |
+
if 'x86_64' in arch:
|
| 154 |
+
return 'X86'
|
| 155 |
+
if 'aarch64' in arch:
|
| 156 |
+
return 'AArch64'
|
| 157 |
+
raise Exception('Unsupported target: %s.' % arch)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def prepare_build(llvm_project_path):
|
| 161 |
+
"""Prepare to build clang."""
|
| 162 |
+
llvm_build_dir = os.path.join(os.getenv('WORK'), 'llvm-build')
|
| 163 |
+
if not os.path.exists(llvm_build_dir):
|
| 164 |
+
os.mkdir(llvm_build_dir)
|
| 165 |
+
execute([
|
| 166 |
+
'cmake', '-G', 'Ninja', '-DLIBCXX_ENABLE_SHARED=OFF',
|
| 167 |
+
'-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON', '-DLIBCXXABI_ENABLE_SHARED=OFF',
|
| 168 |
+
'-DCMAKE_BUILD_TYPE=Release',
|
| 169 |
+
'-DLLVM_ENABLE_PROJECTS=libcxx;libcxxabi;compiler-rt;clang',
|
| 170 |
+
'-DLLVM_TARGETS_TO_BUILD=' + get_clang_target_arch(),
|
| 171 |
+
os.path.join(llvm_project_path, 'llvm')
|
| 172 |
+
],
|
| 173 |
+
env=get_clang_build_env(),
|
| 174 |
+
cwd=llvm_build_dir)
|
| 175 |
+
return llvm_build_dir
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def build_clang(llvm_project_path):
|
| 179 |
+
"""Checkout, build and install Clang."""
|
| 180 |
+
# TODO(metzman): Merge Python checkout and build code with
|
| 181 |
+
# checkout_build_install_llvm.sh.
|
| 182 |
+
# TODO(metzman): Look into speeding this process using ccache.
|
| 183 |
+
# TODO(metzman): Make this program capable of handling MSAN and i386 Clang
|
| 184 |
+
# regressions.
|
| 185 |
+
llvm_build_dir = prepare_build(llvm_project_path)
|
| 186 |
+
execute(['ninja', '-C', llvm_build_dir, 'install'], env=get_clang_build_env())
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def find_culprit_commit(test_command, good_commit, bad_commit):
|
| 190 |
+
"""Returns the culprit LLVM commit that introduced a bug revealed by running
|
| 191 |
+
|test_command|. Uses git bisect and treats |good_commit| as the first latest
|
| 192 |
+
known good commit and |bad_commit| as the first known bad commit."""
|
| 193 |
+
llvm_project_path = os.path.join(os.getenv('SRC'), 'llvm-project')
|
| 194 |
+
clone_with_retries('https://github.com/llvm/llvm-project.git',
|
| 195 |
+
llvm_project_path)
|
| 196 |
+
git_repo = GitRepo(llvm_project_path)
|
| 197 |
+
result = git_repo.bisect(good_commit, bad_commit, test_command)
|
| 198 |
+
print('Culprit commit', result)
|
| 199 |
+
return result
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def main():
|
| 203 |
+
# pylint: disable=line-too-long
|
| 204 |
+
"""Finds the culprit LLVM commit that introduced a clang regression.
|
| 205 |
+
Can be tested using this command in a libsodium shell:
|
| 206 |
+
python3 bisect_clang.py "cd /src/libsodium; make clean; cd -; compile && /out/secret_key_auth_fuzzer -runs=100" \
|
| 207 |
+
f7e52fbdb5a7af8ea0808e98458b497125a5eca1 \
|
| 208 |
+
8288453f6aac05080b751b680455349e09d49825
|
| 209 |
+
"""
|
| 210 |
+
# pylint: enable=line-too-long
|
| 211 |
+
# TODO(metzman): Check CFLAGS for things like -fsanitize=fuzzer-no-link.
|
| 212 |
+
# TODO(metzman): Allow test_command to be optional and for just build.sh to be
|
| 213 |
+
# used instead.
|
| 214 |
+
test_command = sys.argv[1]
|
| 215 |
+
# TODO(metzman): Add in more automation so that the script can automatically
|
| 216 |
+
# determine the commits used in last Clang roll.
|
| 217 |
+
good_commit = sys.argv[2]
|
| 218 |
+
bad_commit = sys.argv[3]
|
| 219 |
+
# TODO(metzman): Make verbosity configurable.
|
| 220 |
+
logging.getLogger().setLevel(logging.DEBUG)
|
| 221 |
+
install_clang_build_deps()
|
| 222 |
+
find_culprit_commit(test_command, good_commit, bad_commit)
|
| 223 |
+
return 0
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
if __name__ == '__main__':
|
| 227 |
+
sys.exit(main())
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/bisect_clang_test.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019 Google Inc.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
#
|
| 15 |
+
################################################################################
|
| 16 |
+
"""Tests for bisect_clang.py"""
|
| 17 |
+
import os
|
| 18 |
+
from unittest import mock
|
| 19 |
+
import unittest
|
| 20 |
+
|
| 21 |
+
import bisect_clang
|
| 22 |
+
|
| 23 |
+
FILE_DIRECTORY = os.path.dirname(__file__)
|
| 24 |
+
LLVM_REPO_PATH = '/llvm-project'
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_git_command(*args):
|
| 28 |
+
"""Returns a git command for the LLVM repo with |args| as arguments."""
|
| 29 |
+
return ['git', '-C', LLVM_REPO_PATH] + list(args)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def patch_environ(testcase_obj):
|
| 33 |
+
"""Patch environment."""
|
| 34 |
+
env = {}
|
| 35 |
+
patcher = mock.patch.dict(os.environ, env)
|
| 36 |
+
testcase_obj.addCleanup(patcher.stop)
|
| 37 |
+
patcher.start()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class BisectClangTestMixin: # pylint: disable=too-few-public-methods
|
| 41 |
+
"""Useful mixin for bisect_clang unittests."""
|
| 42 |
+
|
| 43 |
+
def setUp(self): # pylint: disable=invalid-name
|
| 44 |
+
"""Initialization method for unittests."""
|
| 45 |
+
patch_environ(self)
|
| 46 |
+
os.environ['SRC'] = '/src'
|
| 47 |
+
os.environ['WORK'] = '/work'
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class GetClangBuildEnvTest(BisectClangTestMixin, unittest.TestCase):
|
| 51 |
+
"""Tests for get_clang_build_env."""
|
| 52 |
+
|
| 53 |
+
def test_cflags(self):
|
| 54 |
+
"""Test that CFLAGS are not used compiling clang."""
|
| 55 |
+
os.environ['CFLAGS'] = 'blah'
|
| 56 |
+
self.assertNotIn('CFLAGS', bisect_clang.get_clang_build_env())
|
| 57 |
+
|
| 58 |
+
def test_cxxflags(self):
|
| 59 |
+
"""Test that CXXFLAGS are not used compiling clang."""
|
| 60 |
+
os.environ['CXXFLAGS'] = 'blah'
|
| 61 |
+
self.assertNotIn('CXXFLAGS', bisect_clang.get_clang_build_env())
|
| 62 |
+
|
| 63 |
+
def test_other_variables(self):
|
| 64 |
+
"""Test that other env vars are used when compiling clang."""
|
| 65 |
+
key = 'other'
|
| 66 |
+
value = 'blah'
|
| 67 |
+
os.environ[key] = value
|
| 68 |
+
self.assertEqual(value, bisect_clang.get_clang_build_env()[key])
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def read_test_data(filename):
|
| 72 |
+
"""Returns data from |filename| in the test_data directory."""
|
| 73 |
+
with open(os.path.join(FILE_DIRECTORY, 'test_data', filename)) as file_handle:
|
| 74 |
+
return file_handle.read()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class SearchBisectOutputTest(BisectClangTestMixin, unittest.TestCase):
|
| 78 |
+
"""Tests for search_bisect_output."""
|
| 79 |
+
|
| 80 |
+
def test_search_bisect_output(self):
|
| 81 |
+
"""Test that search_bisect_output finds the responsible commit when one
|
| 82 |
+
exists."""
|
| 83 |
+
test_data = read_test_data('culprit-commit.txt')
|
| 84 |
+
self.assertEqual('ac9ee01fcbfac745aaedca0393a8e1c8a33acd8d',
|
| 85 |
+
bisect_clang.search_bisect_output(test_data))
|
| 86 |
+
|
| 87 |
+
def test_search_bisect_output_none(self):
|
| 88 |
+
"""Test that search_bisect_output doesnt find a non-existent culprit
|
| 89 |
+
commit."""
|
| 90 |
+
self.assertIsNone(bisect_clang.search_bisect_output('hello'))
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def create_mock_popen(
|
| 94 |
+
output=bytes('', 'utf-8'), err=bytes('', 'utf-8'), returncode=0):
|
| 95 |
+
"""Creates a mock subprocess.Popen."""
|
| 96 |
+
|
| 97 |
+
class MockPopen:
|
| 98 |
+
"""Mock subprocess.Popen."""
|
| 99 |
+
commands = []
|
| 100 |
+
testcases_written = []
|
| 101 |
+
|
| 102 |
+
def __init__(self, command, *args, **kwargs): # pylint: disable=unused-argument
|
| 103 |
+
"""Inits the MockPopen."""
|
| 104 |
+
stdout = kwargs.pop('stdout', None)
|
| 105 |
+
self.command = command
|
| 106 |
+
self.commands.append(command)
|
| 107 |
+
self.stdout = None
|
| 108 |
+
self.stderr = None
|
| 109 |
+
self.returncode = returncode
|
| 110 |
+
if hasattr(stdout, 'write'):
|
| 111 |
+
self.stdout = stdout
|
| 112 |
+
|
| 113 |
+
def communicate(self, input_data=None): # pylint: disable=unused-argument
|
| 114 |
+
"""Mock subprocess.Popen.communicate."""
|
| 115 |
+
if self.stdout:
|
| 116 |
+
self.stdout.write(output)
|
| 117 |
+
|
| 118 |
+
if self.stderr:
|
| 119 |
+
self.stderr.write(err)
|
| 120 |
+
|
| 121 |
+
return output, err
|
| 122 |
+
|
| 123 |
+
def poll(self, input_data=None): # pylint: disable=unused-argument
|
| 124 |
+
"""Mock subprocess.Popen.poll."""
|
| 125 |
+
return self.returncode
|
| 126 |
+
|
| 127 |
+
return MockPopen
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def mock_prepare_build_impl(llvm_project_path): # pylint: disable=unused-argument
|
| 131 |
+
"""Mocked prepare_build function."""
|
| 132 |
+
return '/work/llvm-build'
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class BuildClangTest(BisectClangTestMixin, unittest.TestCase):
|
| 136 |
+
"""Tests for build_clang."""
|
| 137 |
+
|
| 138 |
+
def test_build_clang_test(self):
|
| 139 |
+
"""Tests that build_clang works as intended."""
|
| 140 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 141 |
+
with mock.patch('bisect_clang.prepare_build', mock_prepare_build_impl):
|
| 142 |
+
llvm_src_dir = '/src/llvm-project'
|
| 143 |
+
bisect_clang.build_clang(llvm_src_dir)
|
| 144 |
+
self.assertEqual([['ninja', '-C', '/work/llvm-build', 'install']],
|
| 145 |
+
mock_popen.commands)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class GitRepoTest(BisectClangTestMixin, unittest.TestCase):
|
| 149 |
+
"""Tests for GitRepo."""
|
| 150 |
+
|
| 151 |
+
# TODO(metzman): Mock filesystem. Until then, use a real directory.
|
| 152 |
+
|
| 153 |
+
def setUp(self):
|
| 154 |
+
super().setUp()
|
| 155 |
+
self.git = bisect_clang.GitRepo(LLVM_REPO_PATH)
|
| 156 |
+
self.good_commit = 'good_commit'
|
| 157 |
+
self.bad_commit = 'bad_commit'
|
| 158 |
+
self.test_command = 'testcommand'
|
| 159 |
+
|
| 160 |
+
def test_do_command(self):
|
| 161 |
+
"""Test do_command creates a new process as intended."""
|
| 162 |
+
# TODO(metzman): Test directory changing behavior.
|
| 163 |
+
command = ['subcommand', '--option']
|
| 164 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 165 |
+
self.git.do_command(command)
|
| 166 |
+
self.assertEqual([get_git_command('subcommand', '--option')],
|
| 167 |
+
mock_popen.commands)
|
| 168 |
+
|
| 169 |
+
def _test_test_start_commit_unexpected(self, label, commit, returncode):
|
| 170 |
+
"""Tests test_start_commit works as intended when the test returns an
|
| 171 |
+
unexpected value."""
|
| 172 |
+
|
| 173 |
+
def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
|
| 174 |
+
if command == self.test_command:
|
| 175 |
+
return returncode, '', ''
|
| 176 |
+
return 0, '', ''
|
| 177 |
+
|
| 178 |
+
with mock.patch('bisect_clang.execute', mock_execute_impl):
|
| 179 |
+
with mock.patch('bisect_clang.prepare_build', mock_prepare_build_impl):
|
| 180 |
+
with self.assertRaises(bisect_clang.BisectError):
|
| 181 |
+
self.git.test_start_commit(commit, label, self.test_command)
|
| 182 |
+
|
| 183 |
+
def test_test_start_commit_bad_zero(self):
|
| 184 |
+
"""Tests test_start_commit works as intended when the test on the first bad
|
| 185 |
+
commit returns 0."""
|
| 186 |
+
self._test_test_start_commit_unexpected('bad', self.bad_commit, 0)
|
| 187 |
+
|
| 188 |
+
def test_test_start_commit_good_nonzero(self):
|
| 189 |
+
"""Tests test_start_commit works as intended when the test on the first good
|
| 190 |
+
commit returns nonzero."""
|
| 191 |
+
self._test_test_start_commit_unexpected('good', self.good_commit, 1)
|
| 192 |
+
|
| 193 |
+
def test_test_start_commit_good_zero(self):
|
| 194 |
+
"""Tests test_start_commit works as intended when the test on the first good
|
| 195 |
+
commit returns 0."""
|
| 196 |
+
self._test_test_start_commit_expected('good', self.good_commit, 0) # pylint: disable=no-value-for-parameter
|
| 197 |
+
|
| 198 |
+
@mock.patch('bisect_clang.build_clang')
|
| 199 |
+
def _test_test_start_commit_expected(self, label, commit, returncode,
|
| 200 |
+
mock_build_clang):
|
| 201 |
+
"""Tests test_start_commit works as intended when the test returns an
|
| 202 |
+
expected value."""
|
| 203 |
+
command_args = []
|
| 204 |
+
|
| 205 |
+
def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
|
| 206 |
+
command_args.append(command)
|
| 207 |
+
if command == self.test_command:
|
| 208 |
+
return returncode, '', ''
|
| 209 |
+
return 0, '', ''
|
| 210 |
+
|
| 211 |
+
with mock.patch('bisect_clang.execute', mock_execute_impl):
|
| 212 |
+
self.git.test_start_commit(commit, label, self.test_command)
|
| 213 |
+
self.assertEqual([
|
| 214 |
+
get_git_command('checkout', commit), self.test_command,
|
| 215 |
+
get_git_command('bisect', label)
|
| 216 |
+
], command_args)
|
| 217 |
+
mock_build_clang.assert_called_once_with(LLVM_REPO_PATH)
|
| 218 |
+
|
| 219 |
+
def test_test_start_commit_bad_nonzero(self):
|
| 220 |
+
"""Tests test_start_commit works as intended when the test on the first bad
|
| 221 |
+
commit returns nonzero."""
|
| 222 |
+
self._test_test_start_commit_expected('bad', self.bad_commit, 1) # pylint: disable=no-value-for-parameter
|
| 223 |
+
|
| 224 |
+
@mock.patch('bisect_clang.GitRepo.test_start_commit')
|
| 225 |
+
def test_bisect_start(self, mock_test_start_commit):
|
| 226 |
+
"""Tests bisect_start works as intended."""
|
| 227 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 228 |
+
self.git.bisect_start(self.good_commit, self.bad_commit,
|
| 229 |
+
self.test_command)
|
| 230 |
+
self.assertEqual(get_git_command('bisect', 'start'),
|
| 231 |
+
mock_popen.commands[0])
|
| 232 |
+
mock_test_start_commit.assert_has_calls([
|
| 233 |
+
mock.call('bad_commit', 'bad', 'testcommand'),
|
| 234 |
+
mock.call('good_commit', 'good', 'testcommand')
|
| 235 |
+
])
|
| 236 |
+
|
| 237 |
+
def test_do_bisect_command(self):
|
| 238 |
+
"""Test do_bisect_command executes a git bisect subcommand as intended."""
|
| 239 |
+
subcommand = 'subcommand'
|
| 240 |
+
with mock.patch('subprocess.Popen', create_mock_popen()) as mock_popen:
|
| 241 |
+
self.git.do_bisect_command(subcommand)
|
| 242 |
+
self.assertEqual([get_git_command('bisect', subcommand)],
|
| 243 |
+
mock_popen.commands)
|
| 244 |
+
|
| 245 |
+
@mock.patch('bisect_clang.build_clang')
|
| 246 |
+
def _test_test_commit(self, label, output, returncode, mock_build_clang):
|
| 247 |
+
"""Test test_commit works as intended."""
|
| 248 |
+
command_args = []
|
| 249 |
+
|
| 250 |
+
def mock_execute_impl(command, *args, **kwargs): # pylint: disable=unused-argument
|
| 251 |
+
command_args.append(command)
|
| 252 |
+
if command == self.test_command:
|
| 253 |
+
return returncode, output, ''
|
| 254 |
+
return 0, output, ''
|
| 255 |
+
|
| 256 |
+
with mock.patch('bisect_clang.execute', mock_execute_impl):
|
| 257 |
+
result = self.git.test_commit(self.test_command)
|
| 258 |
+
self.assertEqual([self.test_command,
|
| 259 |
+
get_git_command('bisect', label)], command_args)
|
| 260 |
+
mock_build_clang.assert_called_once_with(LLVM_REPO_PATH)
|
| 261 |
+
return result
|
| 262 |
+
|
| 263 |
+
def test_test_commit_good(self):
|
| 264 |
+
"""Test test_commit labels a good commit as good."""
|
| 265 |
+
self.assertIsNone(self._test_test_commit('good', '', 0)) # pylint: disable=no-value-for-parameter
|
| 266 |
+
|
| 267 |
+
def test_test_commit_bad(self):
|
| 268 |
+
"""Test test_commit labels a bad commit as bad."""
|
| 269 |
+
self.assertIsNone(self._test_test_commit('bad', '', 1)) # pylint: disable=no-value-for-parameter
|
| 270 |
+
|
| 271 |
+
def test_test_commit_culprit(self):
|
| 272 |
+
"""Test test_commit returns the culprit"""
|
| 273 |
+
test_data = read_test_data('culprit-commit.txt')
|
| 274 |
+
self.assertEqual('ac9ee01fcbfac745aaedca0393a8e1c8a33acd8d',
|
| 275 |
+
self._test_test_commit('good', test_data, 0)) # pylint: disable=no-value-for-parameter
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
class GetTargetArchToBuildTest(unittest.TestCase):
|
| 279 |
+
"""Tests for get_target_arch_to_build."""
|
| 280 |
+
|
| 281 |
+
def test_unrecognized(self):
|
| 282 |
+
"""Test that an unrecognized architecture raises an exception."""
|
| 283 |
+
with mock.patch('bisect_clang.execute') as mock_execute:
|
| 284 |
+
mock_execute.return_value = (None, 'mips', None)
|
| 285 |
+
with self.assertRaises(Exception):
|
| 286 |
+
bisect_clang.get_clang_target_arch()
|
| 287 |
+
|
| 288 |
+
def test_recognized(self):
|
| 289 |
+
"""Test that a recognized architecture returns the expected value."""
|
| 290 |
+
arch_pairs = {'x86_64': 'X86', 'aarch64': 'AArch64'}
|
| 291 |
+
for uname_result, clang_target in arch_pairs.items():
|
| 292 |
+
with mock.patch('bisect_clang.execute') as mock_execute:
|
| 293 |
+
mock_execute.return_value = (None, uname_result, None)
|
| 294 |
+
self.assertEqual(clang_target, bisect_clang.get_clang_target_arch())
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/cargo
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2020 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 |
+
# This is a wrapper around calling cargo
|
| 17 |
+
# This just expands RUSTFLAGS in case of a coverage build
|
| 18 |
+
# We need this until https://github.com/rust-lang/cargo/issues/5450 is merged
|
| 19 |
+
# because cargo uses relative paths for the current crate
|
| 20 |
+
# and absolute paths for its dependencies
|
| 21 |
+
#
|
| 22 |
+
################################################################################
|
| 23 |
+
|
| 24 |
+
if [ "$SANITIZER" = "coverage" ] && [ $1 = "build" ]
|
| 25 |
+
then
|
| 26 |
+
crate_src_abspath=`cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root'`
|
| 27 |
+
export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix src=$crate_src_abspath/src"
|
| 28 |
+
fi
|
| 29 |
+
|
| 30 |
+
if [ "$SANITIZER" = "coverage" ] && [ $1 = "fuzz" ] && [ $2 = "build" ]
|
| 31 |
+
then
|
| 32 |
+
# hack to turn cargo fuzz build into cargo build so as to get coverage
|
| 33 |
+
# cargo fuzz adds "--target" "x86_64-unknown-linux-gnu"
|
| 34 |
+
(
|
| 35 |
+
# go into fuzz directory if not already the case
|
| 36 |
+
cd fuzz || true
|
| 37 |
+
fuzz_src_abspath=`pwd`
|
| 38 |
+
# Default directory is fuzz_targets, but some projects like image-rs use fuzzers.
|
| 39 |
+
while read i; do
|
| 40 |
+
export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix $i=$fuzz_src_abspath/$i"
|
| 41 |
+
# Bash while syntax so that we modify RUSTFLAGS in main shell instead of a subshell.
|
| 42 |
+
done <<< "$(find . -name "*.rs" | cut -d/ -f2 | uniq)"
|
| 43 |
+
# we do not want to trigger debug assertions and stops
|
| 44 |
+
export RUSTFLAGS="$RUSTFLAGS -C debug-assertions=no"
|
| 45 |
+
# do not optimize with --release, leading to Malformed instrumentation profile data
|
| 46 |
+
cargo build --bins
|
| 47 |
+
# copies the build output in the expected target directory
|
| 48 |
+
cd `cargo metadata --format-version 1 --no-deps | jq -r '.target_directory'`
|
| 49 |
+
mkdir -p x86_64-unknown-linux-gnu/release
|
| 50 |
+
cp -r debug/* x86_64-unknown-linux-gnu/release/
|
| 51 |
+
)
|
| 52 |
+
exit 0
|
| 53 |
+
fi
|
| 54 |
+
|
| 55 |
+
/rust/bin/cargo "$@"
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo "---------------------------------------------------------------"
|
| 19 |
+
|
| 20 |
+
sysctl -w vm.mmap_rnd_bits=28
|
| 21 |
+
|
| 22 |
+
OSS_FUZZ_ON_DEMAND="${OSS_FUZZ_ON_DEMAND:-0}"
|
| 23 |
+
|
| 24 |
+
# Used for Rust introspector builds
|
| 25 |
+
RUST_SANITIZER=$SANITIZER
|
| 26 |
+
|
| 27 |
+
if [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 28 |
+
if [ "$FUZZING_ENGINE" != "libfuzzer" ] && [ "$FUZZING_ENGINE" != "wycheproof" ]; then
|
| 29 |
+
echo "ERROR: JVM projects can be fuzzed with libFuzzer or tested with wycheproof engines only."
|
| 30 |
+
exit 1
|
| 31 |
+
fi
|
| 32 |
+
if [ "$SANITIZER" != "address" ] && [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "undefined" ] && [ "$SANITIZER" != "none" ] && [ "$SANITIZER" != "introspector" ]; then
|
| 33 |
+
echo "ERROR: JVM projects can be fuzzed with AddressSanitizer or UndefinedBehaviorSanitizer or Introspector only."
|
| 34 |
+
exit 1
|
| 35 |
+
fi
|
| 36 |
+
if [ "$ARCHITECTURE" != "x86_64" ]; then
|
| 37 |
+
echo "ERROR: JVM projects can be fuzzed on x86_64 architecture only."
|
| 38 |
+
exit 1
|
| 39 |
+
fi
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
if [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 43 |
+
if [ "$SANITIZER" = "introspector" ]; then
|
| 44 |
+
# introspector sanitizer flag will cause cargo build to fail. Rremove it
|
| 45 |
+
# temporarily, RUST_SANITIZER will hold the original sanitizer.
|
| 46 |
+
export SANITIZER=address
|
| 47 |
+
fi
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if [ "$FUZZING_LANGUAGE" = "javascript" ]; then
|
| 52 |
+
if [ "$FUZZING_ENGINE" != "libfuzzer" ]; then
|
| 53 |
+
echo "ERROR: JavaScript projects can be fuzzed with libFuzzer engine only."
|
| 54 |
+
exit 1
|
| 55 |
+
fi
|
| 56 |
+
if [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "none" ]; then
|
| 57 |
+
echo "ERROR: JavaScript projects cannot be fuzzed with sanitizers."
|
| 58 |
+
exit 1
|
| 59 |
+
fi
|
| 60 |
+
if [ "$ARCHITECTURE" != "x86_64" ]; then
|
| 61 |
+
echo "ERROR: JavaScript projects can be fuzzed on x86_64 architecture only."
|
| 62 |
+
exit 1
|
| 63 |
+
fi
|
| 64 |
+
fi
|
| 65 |
+
|
| 66 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 67 |
+
if [ "$FUZZING_ENGINE" != "libfuzzer" ]; then
|
| 68 |
+
echo "ERROR: Python projects can be fuzzed with libFuzzer engine only."
|
| 69 |
+
exit 1
|
| 70 |
+
fi
|
| 71 |
+
if [ "$SANITIZER" != "address" ] && [ "$SANITIZER" != "undefined" ] && [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "introspector" ]; then
|
| 72 |
+
echo "ERROR: Python projects can be fuzzed with AddressSanitizer or UndefinedBehaviorSanitizer or Coverage or Fuzz Introspector only."
|
| 73 |
+
exit 1
|
| 74 |
+
fi
|
| 75 |
+
if [ "$ARCHITECTURE" != "x86_64" ]; then
|
| 76 |
+
echo "ERROR: Python projects can be fuzzed on x86_64 architecture only."
|
| 77 |
+
exit 1
|
| 78 |
+
fi
|
| 79 |
+
fi
|
| 80 |
+
|
| 81 |
+
if [ -z "${SANITIZER_FLAGS-}" ]; then
|
| 82 |
+
FLAGS_VAR="SANITIZER_FLAGS_${SANITIZER}"
|
| 83 |
+
export SANITIZER_FLAGS=${!FLAGS_VAR-}
|
| 84 |
+
fi
|
| 85 |
+
|
| 86 |
+
if [[ $ARCHITECTURE == "i386" ]]; then
|
| 87 |
+
export CFLAGS="-m32 $CFLAGS"
|
| 88 |
+
cp -R /usr/i386/lib/* /usr/local/lib
|
| 89 |
+
cp -R /usr/i386/include/* /usr/local/include
|
| 90 |
+
fi
|
| 91 |
+
|
| 92 |
+
# Don't use a fuzzing engine with Jazzer which has libFuzzer built-in or with
|
| 93 |
+
# FuzzBench which will provide the fuzzing engine.
|
| 94 |
+
if [[ $FUZZING_ENGINE != "none" ]] && [[ $FUZZING_LANGUAGE != "jvm" ]] && [[ "${OSS_FUZZ_ON_DEMAND}" == "0" ]] ; then
|
| 95 |
+
# compile script might override environment, use . to call it.
|
| 96 |
+
. compile_${FUZZING_ENGINE}
|
| 97 |
+
fi
|
| 98 |
+
|
| 99 |
+
if [[ $SANITIZER_FLAGS = *sanitize=memory* ]]
|
| 100 |
+
then
|
| 101 |
+
# Take all libraries from lib/msan
|
| 102 |
+
# export CXXFLAGS_EXTRA="-L/usr/msan/lib $CXXFLAGS_EXTRA"
|
| 103 |
+
cp -R /usr/msan/lib/* /usr/local/lib/x86_64-unknown-linux-gnu/
|
| 104 |
+
cp -R /usr/msan/include/* /usr/local/include
|
| 105 |
+
|
| 106 |
+
echo 'Building without MSan instrumented libraries.'
|
| 107 |
+
fi
|
| 108 |
+
|
| 109 |
+
# Coverage flag overrides.
|
| 110 |
+
COVERAGE_FLAGS_VAR="COVERAGE_FLAGS_${SANITIZER}"
|
| 111 |
+
if [[ -n ${!COVERAGE_FLAGS_VAR+x} ]]
|
| 112 |
+
then
|
| 113 |
+
export COVERAGE_FLAGS="${!COVERAGE_FLAGS_VAR}"
|
| 114 |
+
fi
|
| 115 |
+
|
| 116 |
+
# Only need the default coverage instrumentation for libFuzzer or honggfuzz.
|
| 117 |
+
# Other engines bring their own.
|
| 118 |
+
if [ $FUZZING_ENGINE = "none" ] || [ $FUZZING_ENGINE = "afl" ] || [ $FUZZING_ENGINE = "centipede" ] || [ "${OSS_FUZZ_ON_DEMAND}" != "0" ]; then
|
| 119 |
+
export COVERAGE_FLAGS=
|
| 120 |
+
fi
|
| 121 |
+
|
| 122 |
+
# Rust does not support sanitizers and coverage flags via CFLAGS/CXXFLAGS, so
|
| 123 |
+
# use RUSTFLAGS.
|
| 124 |
+
# FIXME: Support code coverage once support is in.
|
| 125 |
+
# See https://github.com/rust-lang/rust/issues/34701.
|
| 126 |
+
if [ "$RUST_SANITIZER" == "introspector" ]; then
|
| 127 |
+
export RUSTFLAGS="-Cdebuginfo=2 -Cforce-frame-pointers"
|
| 128 |
+
elif [ "$SANITIZER" != "undefined" ] && [ "$SANITIZER" != "coverage" ] && [ "$SANITIZER" != "none" ] && [ "$ARCHITECTURE" != 'i386' ]; then
|
| 129 |
+
export RUSTFLAGS="--cfg fuzzing -Zsanitizer=${SANITIZER} -Cdebuginfo=1 -Cforce-frame-pointers"
|
| 130 |
+
else
|
| 131 |
+
export RUSTFLAGS="--cfg fuzzing -Cdebuginfo=1 -Cforce-frame-pointers"
|
| 132 |
+
fi
|
| 133 |
+
if [ "$SANITIZER" = "coverage" ]
|
| 134 |
+
then
|
| 135 |
+
# link to C++ from comment in f5098035eb1a14aa966c8651d88ea3d64323823d
|
| 136 |
+
export RUSTFLAGS="$RUSTFLAGS -Cinstrument-coverage -C link-arg=-lc++"
|
| 137 |
+
fi
|
| 138 |
+
|
| 139 |
+
# Add Rust libfuzzer flags.
|
| 140 |
+
# See https://github.com/rust-fuzz/libfuzzer/blob/master/build.rs#L12.
|
| 141 |
+
export CUSTOM_LIBFUZZER_PATH="$LIB_FUZZING_ENGINE_DEPRECATED"
|
| 142 |
+
export CUSTOM_LIBFUZZER_STD_CXX=c++
|
| 143 |
+
|
| 144 |
+
export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COVERAGE_FLAGS"
|
| 145 |
+
export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA"
|
| 146 |
+
|
| 147 |
+
if [ "$SANITIZER" = "undefined" ]; then
|
| 148 |
+
# Disable "function" sanitizer for C code for now, because many projects,
|
| 149 |
+
# possibly via legacy C code are affected.
|
| 150 |
+
# The projects should be fixed and this workaround be removed in the future.
|
| 151 |
+
# TODO(#11778):
|
| 152 |
+
# https://github.com/google/oss-fuzz/issues/11778
|
| 153 |
+
export CFLAGS="$CFLAGS -fno-sanitize=function"
|
| 154 |
+
fi
|
| 155 |
+
|
| 156 |
+
if [ "$FUZZING_LANGUAGE" = "go" ]; then
|
| 157 |
+
# required by Go 1.20
|
| 158 |
+
export CXX="${CXX} -lresolv"
|
| 159 |
+
fi
|
| 160 |
+
|
| 161 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 162 |
+
sanitizer_with_fuzzer_lib_dir=`python3 -c "import atheris; import os; print(atheris.path())"`
|
| 163 |
+
sanitizer_with_fuzzer_output_lib=$OUT/sanitizer_with_fuzzer.so
|
| 164 |
+
if [ "$SANITIZER" = "address" ]; then
|
| 165 |
+
cp $sanitizer_with_fuzzer_lib_dir/asan_with_fuzzer.so $sanitizer_with_fuzzer_output_lib
|
| 166 |
+
elif [ "$SANITIZER" = "undefined" ]; then
|
| 167 |
+
cp $sanitizer_with_fuzzer_lib_dir/ubsan_with_fuzzer.so $sanitizer_with_fuzzer_output_lib
|
| 168 |
+
fi
|
| 169 |
+
|
| 170 |
+
# Disable leak checking as it is unsupported.
|
| 171 |
+
export CFLAGS="$CFLAGS -fno-sanitize=function,leak,vptr,"
|
| 172 |
+
export CXXFLAGS="$CXXFLAGS -fno-sanitize=function,leak,vptr"
|
| 173 |
+
fi
|
| 174 |
+
|
| 175 |
+
# Copy latest llvm-symbolizer in $OUT for stack symbolization.
|
| 176 |
+
cp $(which llvm-symbolizer) $OUT/
|
| 177 |
+
|
| 178 |
+
# Copy Jazzer to $OUT if needed.
|
| 179 |
+
if [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 180 |
+
cp $(which jazzer_agent_deploy.jar) $(which jazzer_driver) $(which jazzer_junit.jar) $OUT/
|
| 181 |
+
jazzer_driver_with_sanitizer=$OUT/jazzer_driver_with_sanitizer
|
| 182 |
+
if [ "$SANITIZER" = "address" ]; then
|
| 183 |
+
cat > $jazzer_driver_with_sanitizer << 'EOF'
|
| 184 |
+
#!/bin/bash
|
| 185 |
+
this_dir=$(dirname "$0")
|
| 186 |
+
"$this_dir/jazzer_driver" --asan "$@"
|
| 187 |
+
EOF
|
| 188 |
+
elif [ "$SANITIZER" = "undefined" ]; then
|
| 189 |
+
cat > $jazzer_driver_with_sanitizer << 'EOF'
|
| 190 |
+
#!/bin/bash
|
| 191 |
+
this_dir=$(dirname "$0")
|
| 192 |
+
"$this_dir/jazzer_driver" --ubsan "$@"
|
| 193 |
+
EOF
|
| 194 |
+
elif [ "$SANITIZER" = "coverage" ] || [ "$SANITIZER" = "introspector" ]; then
|
| 195 |
+
# Coverage & introspector builds require no instrumentation.
|
| 196 |
+
cp $(which jazzer_driver) $jazzer_driver_with_sanitizer
|
| 197 |
+
fi
|
| 198 |
+
chmod +x $jazzer_driver_with_sanitizer
|
| 199 |
+
|
| 200 |
+
# Disable leak checking since the JVM triggers too many false positives.
|
| 201 |
+
export CFLAGS="$CFLAGS -fno-sanitize=leak"
|
| 202 |
+
export CXXFLAGS="$CXXFLAGS -fno-sanitize=leak"
|
| 203 |
+
fi
|
| 204 |
+
|
| 205 |
+
if [ "$SANITIZER" = "introspector" ] || [ "$RUST_SANITIZER" = "introspector" ]; then
|
| 206 |
+
export AR=llvm-ar
|
| 207 |
+
export NM=llvm-nm
|
| 208 |
+
export RANLIB=llvm-ranlib
|
| 209 |
+
|
| 210 |
+
export CFLAGS="$CFLAGS -g"
|
| 211 |
+
export CXXFLAGS="$CXXFLAGS -g"
|
| 212 |
+
export FI_BRANCH_PROFILE=1
|
| 213 |
+
export FUZZ_INTROSPECTOR=1
|
| 214 |
+
export FUZZ_INTROSPECTOR_AUTO_FUZZ=1
|
| 215 |
+
|
| 216 |
+
# Move ar and ranlib
|
| 217 |
+
mv /usr/bin/ar /usr/bin/old-ar
|
| 218 |
+
mv /usr/bin/nm /usr/bin/old-nm
|
| 219 |
+
mv /usr/bin/ranlib /usr/bin/old-ranlib
|
| 220 |
+
|
| 221 |
+
ln -sf /usr/local/bin/llvm-ar /usr/bin/ar
|
| 222 |
+
ln -sf /usr/local/bin/llvm-nm /usr/bin/nm
|
| 223 |
+
ln -sf /usr/local/bin/llvm-ranlib /usr/bin/ranlib
|
| 224 |
+
|
| 225 |
+
apt-get install -y libjpeg-dev zlib1g-dev libyaml-dev
|
| 226 |
+
python3 -m pip install --upgrade pip setuptools
|
| 227 |
+
python3 -m pip install cxxfilt pyyaml beautifulsoup4 lxml soupsieve rust-demangler
|
| 228 |
+
python3 -m pip install --prefer-binary matplotlib
|
| 229 |
+
|
| 230 |
+
# Install Fuzz-Introspector
|
| 231 |
+
pushd /fuzz-introspector/src
|
| 232 |
+
python3 -m pip install -e .
|
| 233 |
+
popd
|
| 234 |
+
|
| 235 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 236 |
+
python3 /fuzz-introspector/src/main.py light --language=python
|
| 237 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 238 |
+
elif [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 239 |
+
python3 /fuzz-introspector/src/main.py light --language=jvm
|
| 240 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 241 |
+
elif [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 242 |
+
python3 /fuzz-introspector/src/main.py light --language=rust
|
| 243 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 244 |
+
else
|
| 245 |
+
python3 /fuzz-introspector/src/main.py light
|
| 246 |
+
|
| 247 |
+
# Make a copy of the light. This is needed because we run two versions of
|
| 248 |
+
# introspector: one based on pure statis analysis and one based on
|
| 249 |
+
# regular LTO.
|
| 250 |
+
cp -rf $SRC/inspector/ /tmp/inspector-saved
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
# Move coverage report.
|
| 254 |
+
if [ -d "$OUT/textcov_reports" ]
|
| 255 |
+
then
|
| 256 |
+
find $OUT/textcov_reports/ -name "*.covreport" -exec cp {} $SRC/inspector/ \;
|
| 257 |
+
find $OUT/textcov_reports/ -name "*.json" -exec cp {} $SRC/inspector/ \;
|
| 258 |
+
fi
|
| 259 |
+
|
| 260 |
+
# Make fuzz-introspector HTML report using light approach.
|
| 261 |
+
REPORT_ARGS="--name=$PROJECT_NAME"
|
| 262 |
+
|
| 263 |
+
# Only pass coverage_url when COVERAGE_URL is set (in cloud builds)
|
| 264 |
+
if [[ ! -z "${COVERAGE_URL+x}" ]]; then
|
| 265 |
+
REPORT_ARGS="$REPORT_ARGS --coverage-url=${COVERAGE_URL}"
|
| 266 |
+
fi
|
| 267 |
+
|
| 268 |
+
# Run pure static analysis fuzz introspector
|
| 269 |
+
fuzz-introspector full --target-dir=$SRC \
|
| 270 |
+
--language=${FUZZING_LANGUAGE} \
|
| 271 |
+
--out-dir=$SRC/inspector \
|
| 272 |
+
${REPORT_ARGS}
|
| 273 |
+
fi
|
| 274 |
+
|
| 275 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 276 |
+
fi
|
| 277 |
+
|
| 278 |
+
echo "---------------------------------------------------------------"
|
| 279 |
+
echo "CC=$CC"
|
| 280 |
+
echo "CXX=$CXX"
|
| 281 |
+
echo "CFLAGS=$CFLAGS"
|
| 282 |
+
echo "CXXFLAGS=$CXXFLAGS"
|
| 283 |
+
echo "RUSTFLAGS=$RUSTFLAGS"
|
| 284 |
+
echo "---------------------------------------------------------------"
|
| 285 |
+
|
| 286 |
+
if [ "${OSS_FUZZ_ON_DEMAND}" != "0" ]; then
|
| 287 |
+
fuzzbench_build
|
| 288 |
+
cp $(which llvm-symbolizer) $OUT/
|
| 289 |
+
exit 0
|
| 290 |
+
fi
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
if [[ ! -z "${CAPTURE_REPLAY_SCRIPT-}" ]]; then
|
| 294 |
+
# Capture a replaying build script which can be used for replaying the build
|
| 295 |
+
# after a vanilla build. This script is meant to be used in a cached
|
| 296 |
+
# container.
|
| 297 |
+
python3 -m pip install bashlex
|
| 298 |
+
python3 /usr/local/bin/bash_parser.py $SRC/build.sh
|
| 299 |
+
fi
|
| 300 |
+
|
| 301 |
+
# Prepare the build command to run the project's build script.
|
| 302 |
+
if [[ ! -z "${REPLAY_ENABLED-}" ]]; then
|
| 303 |
+
# If this is a replay, then use replay_build.sh. This is expected to be
|
| 304 |
+
# running in a cached container where a build has already happened prior.
|
| 305 |
+
BUILD_CMD="bash -eux $SRC/replay_build.sh"
|
| 306 |
+
else
|
| 307 |
+
BUILD_CMD="bash -eux $SRC/build.sh"
|
| 308 |
+
fi
|
| 309 |
+
|
| 310 |
+
# Set +u temporarily to continue even if GOPATH and OSSFUZZ_RUSTPATH are undefined.
|
| 311 |
+
set +u
|
| 312 |
+
# We need to preserve source code files for generating a code coverage report.
|
| 313 |
+
# We need exact files that were compiled, so copy both $SRC and $WORK dirs.
|
| 314 |
+
COPY_SOURCES_CMD="cp -rL --parents $SRC $WORK /usr/include /usr/local/include $GOPATH $OSSFUZZ_RUSTPATH /rustc $OUT"
|
| 315 |
+
set -u
|
| 316 |
+
|
| 317 |
+
if [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 318 |
+
# Copy rust std lib to its path with a hash.
|
| 319 |
+
export rustch=`rustc --version --verbose | grep commit-hash | cut -d' ' -f2`
|
| 320 |
+
mkdir -p /rustc/$rustch/
|
| 321 |
+
export rustdef=`rustup toolchain list | grep default | cut -d' ' -f1`
|
| 322 |
+
cp -r /rust/rustup/toolchains/$rustdef/lib/rustlib/src/rust/library/ /rustc/$rustch/
|
| 323 |
+
fi
|
| 324 |
+
|
| 325 |
+
if [ "${BUILD_UID-0}" -ne "0" ]; then
|
| 326 |
+
adduser -u $BUILD_UID --disabled-password --gecos '' builder
|
| 327 |
+
chown -R builder $SRC $OUT $WORK
|
| 328 |
+
su -c "$BUILD_CMD" builder
|
| 329 |
+
if [ "$SANITIZER" = "coverage" ]; then
|
| 330 |
+
# Some directories have broken symlinks (e.g. honggfuzz), ignore the errors.
|
| 331 |
+
su -c "$COPY_SOURCES_CMD" builder 2>/dev/null || true
|
| 332 |
+
fi
|
| 333 |
+
else
|
| 334 |
+
$BUILD_CMD
|
| 335 |
+
if [ "$SANITIZER" = "coverage" ]; then
|
| 336 |
+
# Some directories have broken symlinks (e.g. honggfuzz), ignore the errors.
|
| 337 |
+
$COPY_SOURCES_CMD 2>/dev/null || true
|
| 338 |
+
fi
|
| 339 |
+
fi
|
| 340 |
+
|
| 341 |
+
if [ "$SANITIZER" = "introspector" ] || [ "$RUST_SANITIZER" = "introspector" ]; then
|
| 342 |
+
unset CXXFLAGS
|
| 343 |
+
unset CFLAGS
|
| 344 |
+
export G_ANALYTICS_TAG="G-8WTFM1Y62J"
|
| 345 |
+
|
| 346 |
+
# If we get to here, it means the e.g. LTO had no problems and succeeded.
|
| 347 |
+
# TO this end, we wlil restore the original light analysis and used the
|
| 348 |
+
# LTO processing itself.
|
| 349 |
+
rm -rf $SRC/inspector
|
| 350 |
+
cp -rf /tmp/inspector-saved $SRC/inspector
|
| 351 |
+
|
| 352 |
+
cd /fuzz-introspector/src
|
| 353 |
+
python3 -m pip install -e .
|
| 354 |
+
cd /src/
|
| 355 |
+
|
| 356 |
+
if [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 357 |
+
# Restore the sanitizer flag for rust
|
| 358 |
+
export SANITIZER="introspector"
|
| 359 |
+
fi
|
| 360 |
+
|
| 361 |
+
mkdir -p $SRC/inspector
|
| 362 |
+
find $SRC/ -name "fuzzerLogFile-*.data" -exec cp {} $SRC/inspector/ \;
|
| 363 |
+
find $SRC/ -name "fuzzerLogFile-*.data.yaml" -exec cp {} $SRC/inspector/ \;
|
| 364 |
+
find $SRC/ -name "fuzzerLogFile-*.data.debug_*" -exec cp {} $SRC/inspector/ \;
|
| 365 |
+
find $SRC/ -name "allFunctionsWithMain-*.yaml" -exec cp {} $SRC/inspector/ \;
|
| 366 |
+
|
| 367 |
+
# Move coverage report.
|
| 368 |
+
if [ -d "$OUT/textcov_reports" ]
|
| 369 |
+
then
|
| 370 |
+
find $OUT/textcov_reports/ -name "*.covreport" -exec cp {} $SRC/inspector/ \;
|
| 371 |
+
find $OUT/textcov_reports/ -name "*.json" -exec cp {} $SRC/inspector/ \;
|
| 372 |
+
fi
|
| 373 |
+
|
| 374 |
+
cd $SRC/inspector
|
| 375 |
+
|
| 376 |
+
# Make fuzz-introspector HTML report.
|
| 377 |
+
REPORT_ARGS="--name=$PROJECT_NAME"
|
| 378 |
+
# Only pass coverage_url when COVERAGE_URL is set (in cloud builds)
|
| 379 |
+
if [[ ! -z "${COVERAGE_URL+x}" ]]; then
|
| 380 |
+
REPORT_ARGS="$REPORT_ARGS --coverage-url=${COVERAGE_URL}"
|
| 381 |
+
fi
|
| 382 |
+
|
| 383 |
+
# Do different things depending on languages
|
| 384 |
+
if [ "$FUZZING_LANGUAGE" = "python" ]; then
|
| 385 |
+
echo "GOING python route"
|
| 386 |
+
set -x
|
| 387 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
|
| 388 |
+
REPORT_ARGS="$REPORT_ARGS --language=python"
|
| 389 |
+
fuzz-introspector report $REPORT_ARGS
|
| 390 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 391 |
+
elif [ "$FUZZING_LANGUAGE" = "jvm" ]; then
|
| 392 |
+
echo "GOING jvm route"
|
| 393 |
+
set -x
|
| 394 |
+
find $OUT/ -name "jacoco.xml" -exec cp {} $SRC/inspector/ \;
|
| 395 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC --out-dir=$SRC/inspector"
|
| 396 |
+
REPORT_ARGS="$REPORT_ARGS --language=jvm"
|
| 397 |
+
fuzz-introspector full $REPORT_ARGS
|
| 398 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 399 |
+
elif [ "$FUZZING_LANGUAGE" = "rust" ]; then
|
| 400 |
+
echo "GOING rust route"
|
| 401 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC --out-dir=$SRC/inspector"
|
| 402 |
+
REPORT_ARGS="$REPORT_ARGS --language=rust"
|
| 403 |
+
fuzz-introspector full $REPORT_ARGS
|
| 404 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 405 |
+
else
|
| 406 |
+
# C/C++
|
| 407 |
+
mkdir -p $SRC/inspector
|
| 408 |
+
# Correlate fuzzer binaries to fuzz-introspector's raw data
|
| 409 |
+
fuzz-introspector correlate --binaries-dir=$OUT/
|
| 410 |
+
|
| 411 |
+
# Generate fuzz-introspector HTML report, this generates
|
| 412 |
+
# the file exe_to_fuzz_introspector_logs.yaml
|
| 413 |
+
REPORT_ARGS="$REPORT_ARGS --target-dir=$SRC/inspector"
|
| 414 |
+
# Use the just-generated correlation file
|
| 415 |
+
REPORT_ARGS="$REPORT_ARGS --correlation-file=exe_to_fuzz_introspector_logs.yaml"
|
| 416 |
+
fuzz-introspector report $REPORT_ARGS
|
| 417 |
+
|
| 418 |
+
rsync -avu --delete "$SRC/inspector/" "$OUT/inspector"
|
| 419 |
+
fi
|
| 420 |
+
fi
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_afl
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# If LLVM once again does weird changes then enable this:
|
| 19 |
+
#export AFL_LLVM_INSTRUMENT=LLVM-NATIVE
|
| 20 |
+
|
| 21 |
+
# AFL++ setup
|
| 22 |
+
echo "Copying precompiled AFL++"
|
| 23 |
+
|
| 24 |
+
# Copy AFL++ tools necessary for fuzzing.
|
| 25 |
+
pushd $SRC/aflplusplus > /dev/null
|
| 26 |
+
|
| 27 |
+
cp -f libAFLDriver.a $LIB_FUZZING_ENGINE
|
| 28 |
+
|
| 29 |
+
# Some important projects include libraries, copy those even when they don't
|
| 30 |
+
# start with "afl-". Use "sort -u" to avoid a warning about duplicates.
|
| 31 |
+
ls afl-* *.txt *.a *.o *.so | sort -u | xargs cp -t $OUT
|
| 32 |
+
export CC="$SRC/aflplusplus/afl-clang-fast"
|
| 33 |
+
export CXX="$SRC/aflplusplus/afl-clang-fast++"
|
| 34 |
+
|
| 35 |
+
# Set sane AFL++ environment defaults:
|
| 36 |
+
# Be quiet, otherwise this can break some builds.
|
| 37 |
+
export AFL_QUIET=1
|
| 38 |
+
# No leak errors during builds.
|
| 39 |
+
export ASAN_OPTIONS="detect_leaks=0:symbolize=0:detect_odr_violation=0:abort_on_error=1"
|
| 40 |
+
# Do not abort on any problems (because this is during build where it is ok)
|
| 41 |
+
export AFL_IGNORE_PROBLEMS=1
|
| 42 |
+
# No complain on unknown AFL environment variables
|
| 43 |
+
export AFL_IGNORE_UNKNOWN_ENVS=1
|
| 44 |
+
|
| 45 |
+
# Provide a way to document the AFL++ options used in this build:
|
| 46 |
+
echo
|
| 47 |
+
echo AFL++ target compilation setup:
|
| 48 |
+
env | egrep '^AFL_' | tee "$OUT/afl_options.txt"
|
| 49 |
+
echo
|
| 50 |
+
|
| 51 |
+
popd > /dev/null
|
| 52 |
+
|
| 53 |
+
echo " done."
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_honggfuzz
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo "Skipping compilation; using precompiled honggfuzz"
|
| 19 |
+
|
| 20 |
+
cp $SRC/honggfuzz/honggfuzz.a $LIB_FUZZING_ENGINE
|
| 21 |
+
cp $SRC/honggfuzz/honggfuzz $OUT/
|
| 22 |
+
|
| 23 |
+
# Set flags necessary for netdriver compilation.
|
| 24 |
+
export LIB_HFND="-Wl,-u,LIBHFNETDRIVER_module_netdriver -Wl,--start-group $SRC/honggfuzz/libhfnetdriver/libhfnetdriver.a $SRC/honggfuzz/libhfcommon/libhfcommon.a -Wl,--end-group"
|
| 25 |
+
|
| 26 |
+
export HFND_CXXFLAGS='-DHFND_FUZZING_ENTRY_FUNCTION_CXX(x,y)=extern const char* LIBHFNETDRIVER_module_netdriver;const char** LIBHFNETDRIVER_tmp1 = &LIBHFNETDRIVER_module_netdriver;extern "C" int HonggfuzzNetDriver_main(x,y);int HonggfuzzNetDriver_main(x,y)'
|
| 27 |
+
export HFND_CFLAGS='-DHFND_FUZZING_ENTRY_FUNCTION(x,y)=extern const char* LIBHFNETDRIVER_module_netdriver;const char** LIBHFNETDRIVER_tmp1 = &LIBHFNETDRIVER_module_netdriver;int HonggfuzzNetDriver_main(x,y);int HonggfuzzNetDriver_main(x,y)'
|
| 28 |
+
|
| 29 |
+
# Custom coverage flags, roughly in sync with:
|
| 30 |
+
# https://github.com/google/honggfuzz/blob/oss-fuzz/hfuzz_cc/hfuzz-cc.c
|
| 31 |
+
export COVERAGE_FLAGS="-fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp"
|
| 32 |
+
|
| 33 |
+
echo " done."
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_javascript_fuzzer
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2023 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
project=$1
|
| 19 |
+
# Path the fuzz target source file relative to the project's root.
|
| 20 |
+
fuzz_target=$2
|
| 21 |
+
# Arguments to pass to Jazzer.js
|
| 22 |
+
jazzerjs_args=${@:3}
|
| 23 |
+
|
| 24 |
+
# Copy source code into the $OUT directory and install Jazzer.js into the project.
|
| 25 |
+
if [ ! -d $OUT/$project ]; then
|
| 26 |
+
cp -r $SRC/$project $OUT/$project
|
| 27 |
+
fi
|
| 28 |
+
|
| 29 |
+
fuzzer_basename=$(basename -s .js $fuzz_target)
|
| 30 |
+
|
| 31 |
+
# Create an execution wrapper that executes Jazzer.js with the correct arguments.
|
| 32 |
+
echo "#!/bin/bash
|
| 33 |
+
# LLVMFuzzerTestOneInput so that the wrapper script is recognized as a fuzz target for 'check_build'.
|
| 34 |
+
project_dir=\$(dirname \"\$0\")/$project
|
| 35 |
+
\$project_dir/node_modules/@jazzer.js/core/dist/cli.js \$project_dir/$fuzz_target $jazzerjs_args \$JAZZERJS_EXTRA_ARGS -- \$@" > $OUT/$fuzzer_basename
|
| 36 |
+
|
| 37 |
+
chmod +x $OUT/$fuzzer_basename
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_libfuzzer
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo -n "Compiling libFuzzer to $LIB_FUZZING_ENGINE... "
|
| 19 |
+
export LIB_FUZZING_ENGINE="-fsanitize=fuzzer"
|
| 20 |
+
if [ "$FUZZING_LANGUAGE" = "go" ]; then
|
| 21 |
+
export LIB_FUZZING_ENGINE="$LIB_FUZZING_ENGINE $GOPATH/gosigfuzz/gosigfuzz.o"
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
cp /usr/local/lib/clang/*/lib/$ARCHITECTURE-unknown-linux-gnu/libclang_rt.fuzzer.a $LIB_FUZZING_ENGINE_DEPRECATED
|
| 25 |
+
echo " done."
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/compile_python_fuzzer
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# In order to enable PySecSan for a given module, set the environment
|
| 19 |
+
# variable ENABLE_PYSECSAN="YES"
|
| 20 |
+
|
| 21 |
+
fuzzer_path=$1
|
| 22 |
+
shift 1
|
| 23 |
+
|
| 24 |
+
fuzzer_basename=$(basename -s .py $fuzzer_path)
|
| 25 |
+
fuzzer_package=${fuzzer_basename}.pkg
|
| 26 |
+
|
| 27 |
+
PYFUZZ_WORKPATH=$SRC/pyfuzzworkdir/
|
| 28 |
+
FUZZ_WORKPATH=$PYFUZZ_WORKPATH/$fuzzer_basename
|
| 29 |
+
|
| 30 |
+
if [[ $SANITIZER = *introspector* ]]; then
|
| 31 |
+
# Extract the source package the fuzzer targets. This must happen before
|
| 32 |
+
# we enter the virtual environment in the following lines because we need
|
| 33 |
+
# to use the same python environment that installed the fuzzer dependencies.
|
| 34 |
+
python3 /fuzz-introspector/frontends/python/prepare_fuzz_imports.py $fuzzer_path isossfuzz
|
| 35 |
+
|
| 36 |
+
# We must ensure python3.9, this is because we use certain
|
| 37 |
+
# AST logic from there.
|
| 38 |
+
# The below should probably be refined
|
| 39 |
+
apt-get install -y python3.9
|
| 40 |
+
apt-get update
|
| 41 |
+
apt-get install -y python3-pip
|
| 42 |
+
python3.9 -m pip install virtualenv
|
| 43 |
+
python3.9 -m virtualenv .venv
|
| 44 |
+
. .venv/bin/activate
|
| 45 |
+
pip3 install pyyaml
|
| 46 |
+
export PYTHONPATH="/fuzz-introspector/frontends/python/PyCG"
|
| 47 |
+
|
| 48 |
+
ARGS="--fuzzer $fuzzer_path"
|
| 49 |
+
if [ -n "${PYFUZZPACKAGE-}" ]; then
|
| 50 |
+
ARGS="$ARGS --package=${PYFUZZPACKAGE}"
|
| 51 |
+
fi
|
| 52 |
+
python /fuzz-introspector/frontends/python/main.py $ARGS
|
| 53 |
+
ls -la ./
|
| 54 |
+
exit 0
|
| 55 |
+
fi
|
| 56 |
+
|
| 57 |
+
# In coverage mode prepend coverage logic to the fuzzer source
|
| 58 |
+
if [[ $SANITIZER = *coverage* ]]; then
|
| 59 |
+
cat <<EOF > coverage_wrapper.py
|
| 60 |
+
###### Coverage stub
|
| 61 |
+
import atexit
|
| 62 |
+
import coverage
|
| 63 |
+
cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
|
| 64 |
+
cov.start()
|
| 65 |
+
# Register an exist handler that will print coverage
|
| 66 |
+
def exit_handler():
|
| 67 |
+
cov.stop()
|
| 68 |
+
cov.save()
|
| 69 |
+
atexit.register(exit_handler)
|
| 70 |
+
####### End of coverage stub
|
| 71 |
+
EOF
|
| 72 |
+
|
| 73 |
+
# Prepend stub and create tmp file
|
| 74 |
+
cat coverage_wrapper.py $fuzzer_path > tmp_fuzzer_coverage.py
|
| 75 |
+
|
| 76 |
+
# Overwrite existing fuzzer with new fuzzer that has stub
|
| 77 |
+
mv tmp_fuzzer_coverage.py $fuzzer_path
|
| 78 |
+
fi
|
| 79 |
+
|
| 80 |
+
# If PYSECSAN is enabled, ensure that we can build with it.
|
| 81 |
+
if [[ ${ENABLE_PYSECSAN:-"0"} != "0" ]];
|
| 82 |
+
then
|
| 83 |
+
# Make sure pysecsan is installed
|
| 84 |
+
if [[ ! -d "/pysecsan" ]];
|
| 85 |
+
then
|
| 86 |
+
pushd /usr/local/lib/sanitizers/pysecsan
|
| 87 |
+
python3 -m pip install .
|
| 88 |
+
popd
|
| 89 |
+
fi
|
| 90 |
+
|
| 91 |
+
cat <<EOF > pysecsan_wrapper.py
|
| 92 |
+
import pysecsan; pysecsan.add_hooks();
|
| 93 |
+
EOF
|
| 94 |
+
|
| 95 |
+
# Prepend stub and create tmp file
|
| 96 |
+
cat pysecsan_wrapper.py $fuzzer_path > tmp_fuzzer_pysecsan.py
|
| 97 |
+
|
| 98 |
+
# Overwrite existing fuzzer with new fuzzer that has stub
|
| 99 |
+
mv tmp_fuzzer_pysecsan.py $fuzzer_path
|
| 100 |
+
fi
|
| 101 |
+
|
| 102 |
+
rm -rf $PYFUZZ_WORKPATH
|
| 103 |
+
mkdir $PYFUZZ_WORKPATH $FUZZ_WORKPATH
|
| 104 |
+
|
| 105 |
+
pyinstaller --distpath $OUT --workpath=$FUZZ_WORKPATH --onefile --name $fuzzer_package "$@" $fuzzer_path
|
| 106 |
+
|
| 107 |
+
# Disable executable bit from package as OSS-Fuzz uses executable bits to
|
| 108 |
+
# identify fuzz targets. We re-enable the executable bit in wrapper script
|
| 109 |
+
# below.
|
| 110 |
+
chmod -x $OUT/$fuzzer_package
|
| 111 |
+
|
| 112 |
+
# In coverage mode save source files of dependencies in pyinstalled binary
|
| 113 |
+
if [[ $SANITIZER = *coverage* ]]; then
|
| 114 |
+
rm -rf /medio/
|
| 115 |
+
python3 /usr/local/bin/python_coverage_helper.py $FUZZ_WORKPATH "/medio"
|
| 116 |
+
zip -r $fuzzer_package.deps.zip /medio
|
| 117 |
+
mv $fuzzer_package.deps.zip $OUT/
|
| 118 |
+
fi
|
| 119 |
+
|
| 120 |
+
# Create execution wrapper.
|
| 121 |
+
echo "#!/bin/sh
|
| 122 |
+
# LLVMFuzzerTestOneInput for fuzzer detection.
|
| 123 |
+
this_dir=\$(dirname \"\$0\")
|
| 124 |
+
chmod +x \$this_dir/$fuzzer_package
|
| 125 |
+
LD_PRELOAD=\$this_dir/sanitizer_with_fuzzer.so \
|
| 126 |
+
ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \
|
| 127 |
+
\$this_dir/$fuzzer_package \$@" > $OUT/$fuzzer_basename
|
| 128 |
+
chmod +x $OUT/$fuzzer_basename
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/detect_repo.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019 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 to get the the name of a git repo containing a specific commit
|
| 15 |
+
inside of an OSS-Fuzz project.
|
| 16 |
+
|
| 17 |
+
Example Usage:
|
| 18 |
+
|
| 19 |
+
python detect_repo.py --src_dir /src --example_commit
|
| 20 |
+
b534f03eecd8a109db2b085ab24d419b6486de97
|
| 21 |
+
|
| 22 |
+
Prints the location of the git remote repo as well as the repo's name
|
| 23 |
+
seperated by a space.
|
| 24 |
+
|
| 25 |
+
https://github.com/VirusTotal/yara.git yara
|
| 26 |
+
|
| 27 |
+
"""
|
| 28 |
+
import argparse
|
| 29 |
+
import logging
|
| 30 |
+
import os
|
| 31 |
+
import subprocess
|
| 32 |
+
|
| 33 |
+
GO_PATH = '/root/go/src/'
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def main():
|
| 37 |
+
"""Function to get a git repo's url and name referenced by OSS-Fuzz
|
| 38 |
+
Dockerfile.
|
| 39 |
+
|
| 40 |
+
Raises:
|
| 41 |
+
ValueError when a commit or a ref is not provided.
|
| 42 |
+
"""
|
| 43 |
+
parser = argparse.ArgumentParser(
|
| 44 |
+
description=
|
| 45 |
+
'Finds a specific git repo in an oss-fuzz project\'s docker file.')
|
| 46 |
+
parser.add_argument('--repo_name', help='The name of the git repo.')
|
| 47 |
+
parser.add_argument('--src_dir', help='The location of the possible repo.')
|
| 48 |
+
parser.add_argument('--example_commit',
|
| 49 |
+
help='A commit SHA referencing the project\'s main repo.')
|
| 50 |
+
|
| 51 |
+
args = parser.parse_args()
|
| 52 |
+
if not args.repo_name and not args.example_commit:
|
| 53 |
+
raise ValueError(
|
| 54 |
+
'Requires an example commit or a repo name to find repo location.')
|
| 55 |
+
if args.src_dir:
|
| 56 |
+
src_dir = args.src_dir
|
| 57 |
+
else:
|
| 58 |
+
src_dir = os.environ.get('SRC', '/src')
|
| 59 |
+
|
| 60 |
+
for single_dir in get_dirs_to_search(src_dir, args.repo_name):
|
| 61 |
+
full_path = os.path.join(src_dir, single_dir)
|
| 62 |
+
if not os.path.isdir(full_path):
|
| 63 |
+
continue
|
| 64 |
+
if args.example_commit and check_for_commit(full_path, args.example_commit):
|
| 65 |
+
print('Detected repo:', get_repo(full_path), full_path)
|
| 66 |
+
return
|
| 67 |
+
if args.repo_name and check_for_repo_name(full_path, args.repo_name):
|
| 68 |
+
print('Detected repo:', get_repo(full_path), full_path)
|
| 69 |
+
return
|
| 70 |
+
logging.error('No git repos with specific commit: %s found in %s',
|
| 71 |
+
args.example_commit, src_dir)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def get_dirs_to_search(src_dir, repo_name):
|
| 75 |
+
"""Gets a list of directories to search for the main git repo.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
src_dir: The location set for the projects SRC.
|
| 79 |
+
repo_name: The name of the repo you are searching for.
|
| 80 |
+
|
| 81 |
+
Returns:
|
| 82 |
+
A list of directorys to search.
|
| 83 |
+
"""
|
| 84 |
+
dirs_to_search = os.listdir(src_dir)
|
| 85 |
+
if os.path.exists(GO_PATH) and repo_name:
|
| 86 |
+
for root, dirs, _ in os.walk(GO_PATH):
|
| 87 |
+
for test_dir in dirs:
|
| 88 |
+
if repo_name in test_dir:
|
| 89 |
+
dirs_to_search.append(os.path.join(root, test_dir))
|
| 90 |
+
return dirs_to_search
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def get_repo(repo_path):
|
| 94 |
+
"""Gets a git repo link from a specific directory in a docker image.
|
| 95 |
+
|
| 96 |
+
Args:
|
| 97 |
+
repo_path: The directory on the image where the git repo exists.
|
| 98 |
+
|
| 99 |
+
Returns:
|
| 100 |
+
The repo location or None.
|
| 101 |
+
"""
|
| 102 |
+
output, return_code = execute(['git', 'config', '--get', 'remote.origin.url'],
|
| 103 |
+
location=repo_path,
|
| 104 |
+
check_result=True)
|
| 105 |
+
if return_code == 0 and output:
|
| 106 |
+
return output.rstrip()
|
| 107 |
+
return None
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def check_for_repo_name(repo_path, expected_repo_name):
|
| 111 |
+
"""Returns True if the repo at |repo_path| repo_name matches
|
| 112 |
+
|expected_repo_name|.
|
| 113 |
+
|
| 114 |
+
Args:
|
| 115 |
+
repo_path: The directory of a git repo.
|
| 116 |
+
expected_repo_name: The name of the target git repo.
|
| 117 |
+
"""
|
| 118 |
+
if not os.path.exists(os.path.join(repo_path, '.git')):
|
| 119 |
+
return False
|
| 120 |
+
|
| 121 |
+
repo_url, _ = execute(['git', 'config', '--get', 'remote.origin.url'],
|
| 122 |
+
location=repo_path)
|
| 123 |
+
# Handle two common cases:
|
| 124 |
+
# https://github.com/google/syzkaller/
|
| 125 |
+
# https://github.com/google/syzkaller.git
|
| 126 |
+
repo_url = repo_url.replace('.git', '').rstrip().rstrip('/')
|
| 127 |
+
actual_repo_name = repo_url.split('/')[-1]
|
| 128 |
+
return actual_repo_name == expected_repo_name
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def check_for_commit(repo_path, commit):
|
| 132 |
+
"""Checks a directory for a specific commit.
|
| 133 |
+
|
| 134 |
+
Args:
|
| 135 |
+
repo_path: The name of the directory to test for the commit.
|
| 136 |
+
commit: The commit SHA to check for.
|
| 137 |
+
|
| 138 |
+
Returns:
|
| 139 |
+
True if directory contains that commit.
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
# Check if valid git repo.
|
| 143 |
+
if not os.path.exists(os.path.join(repo_path, '.git')):
|
| 144 |
+
return False
|
| 145 |
+
|
| 146 |
+
# Check if history fetch is needed.
|
| 147 |
+
if os.path.exists(os.path.join(repo_path, '.git', 'shallow')):
|
| 148 |
+
execute(['git', 'fetch', '--unshallow'], location=repo_path)
|
| 149 |
+
|
| 150 |
+
# Check if commit is in history.
|
| 151 |
+
_, return_code = execute(['git', 'cat-file', '-e', commit],
|
| 152 |
+
location=repo_path)
|
| 153 |
+
return return_code == 0
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def execute(command, location, check_result=False):
|
| 157 |
+
"""Runs a shell command in the specified directory location.
|
| 158 |
+
|
| 159 |
+
Args:
|
| 160 |
+
command: The command as a list to be run.
|
| 161 |
+
location: The directory the command is run in.
|
| 162 |
+
check_result: Should an exception be thrown on failed command.
|
| 163 |
+
|
| 164 |
+
Returns:
|
| 165 |
+
The stdout of the command, the error code.
|
| 166 |
+
|
| 167 |
+
Raises:
|
| 168 |
+
RuntimeError: running a command resulted in an error.
|
| 169 |
+
"""
|
| 170 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=location)
|
| 171 |
+
output, err = process.communicate()
|
| 172 |
+
if check_result and (process.returncode or err):
|
| 173 |
+
raise RuntimeError(
|
| 174 |
+
'Error: %s\n running command: %s\n return code: %s\n out %s\n' %
|
| 175 |
+
(err, command, process.returncode, output))
|
| 176 |
+
if output is not None:
|
| 177 |
+
output = output.decode('ascii')
|
| 178 |
+
return output, process.returncode
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/detect_repo_test.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2019 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 |
+
"""Test the functionality of the detect_repo module.
|
| 15 |
+
This will consist of the following functional test:
|
| 16 |
+
1. Determine if an OSS-Fuzz projects main repo can be detected from example
|
| 17 |
+
commits.
|
| 18 |
+
2. Determine if an OSS-Fuzz project main repo can be detected from a
|
| 19 |
+
repo name.
|
| 20 |
+
"""
|
| 21 |
+
import os
|
| 22 |
+
import re
|
| 23 |
+
import sys
|
| 24 |
+
import tempfile
|
| 25 |
+
import unittest
|
| 26 |
+
from unittest import mock
|
| 27 |
+
|
| 28 |
+
import detect_repo
|
| 29 |
+
|
| 30 |
+
# Appending to path for access to repo_manager module.
|
| 31 |
+
# pylint: disable=wrong-import-position
|
| 32 |
+
sys.path.append(
|
| 33 |
+
os.path.dirname(os.path.dirname(os.path.dirname(
|
| 34 |
+
os.path.abspath(__file__)))))
|
| 35 |
+
import repo_manager
|
| 36 |
+
import test_repos
|
| 37 |
+
# pylint: enable=wrong-import-position
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class TestCheckForRepoName(unittest.TestCase):
|
| 41 |
+
"""Tests for check_for_repo_name."""
|
| 42 |
+
|
| 43 |
+
@mock.patch('os.path.exists', return_value=True)
|
| 44 |
+
@mock.patch('detect_repo.execute',
|
| 45 |
+
return_value=('https://github.com/google/syzkaller/', None))
|
| 46 |
+
def test_go_get_style_url(self, _, __):
|
| 47 |
+
"""Tests that check_for_repo_name works on repos that were downloaded using
|
| 48 |
+
go get."""
|
| 49 |
+
self.assertTrue(detect_repo.check_for_repo_name('fake-path', 'syzkaller'))
|
| 50 |
+
|
| 51 |
+
@mock.patch('os.path.exists', return_value=True)
|
| 52 |
+
@mock.patch('detect_repo.execute',
|
| 53 |
+
return_value=('https://github.com/google/syzkaller', None))
|
| 54 |
+
def test_missing_git_and_slash_url(self, _, __):
|
| 55 |
+
"""Tests that check_for_repo_name works on repos who's URLs do not end in
|
| 56 |
+
".git" or "/"."""
|
| 57 |
+
self.assertTrue(detect_repo.check_for_repo_name('fake-path', 'syzkaller'))
|
| 58 |
+
|
| 59 |
+
@mock.patch('os.path.exists', return_value=True)
|
| 60 |
+
@mock.patch('detect_repo.execute',
|
| 61 |
+
return_value=('https://github.com/google/syzkaller.git', None))
|
| 62 |
+
def test_normal_style_repo_url(self, _, __):
|
| 63 |
+
"""Tests that check_for_repo_name works on normally cloned repos."""
|
| 64 |
+
self.assertTrue(detect_repo.check_for_repo_name('fake-path', 'syzkaller'))
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@unittest.skipIf(not os.getenv('INTEGRATION_TESTS'),
|
| 68 |
+
'INTEGRATION_TESTS=1 not set')
|
| 69 |
+
class DetectRepoIntegrationTest(unittest.TestCase):
|
| 70 |
+
"""Class to test the functionality of the detect_repo module."""
|
| 71 |
+
|
| 72 |
+
def test_infer_main_repo_from_commit(self):
|
| 73 |
+
"""Tests that the main repo can be inferred based on an example commit."""
|
| 74 |
+
|
| 75 |
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
| 76 |
+
# Construct example repo's to check for commits.
|
| 77 |
+
for test_repo in test_repos.TEST_REPOS:
|
| 78 |
+
repo_manager.clone_repo_and_get_manager(test_repo.git_url, tmp_dir)
|
| 79 |
+
self.check_with_repo(test_repo.git_url,
|
| 80 |
+
test_repo.git_repo_name,
|
| 81 |
+
tmp_dir,
|
| 82 |
+
commit=test_repo.old_commit)
|
| 83 |
+
|
| 84 |
+
def test_infer_main_repo_from_name(self):
|
| 85 |
+
"""Tests that the main project repo can be inferred from a repo name."""
|
| 86 |
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
| 87 |
+
for test_repo in test_repos.TEST_REPOS:
|
| 88 |
+
repo_manager.clone_repo_and_get_manager(test_repo.git_url, tmp_dir)
|
| 89 |
+
self.check_with_repo(test_repo.git_url, test_repo.git_repo_name,
|
| 90 |
+
tmp_dir)
|
| 91 |
+
|
| 92 |
+
def check_with_repo(self, repo_origin, repo_name, tmp_dir, commit=None):
|
| 93 |
+
"""Checks the detect repo's main method for a specific set of inputs.
|
| 94 |
+
|
| 95 |
+
Args:
|
| 96 |
+
repo_origin: URL of the git repo.
|
| 97 |
+
repo_name: The name of the directory it is cloned to.
|
| 98 |
+
tmp_dir: The location of the directory of git repos to be searched.
|
| 99 |
+
commit: The commit that should be used to look up the repo.
|
| 100 |
+
"""
|
| 101 |
+
command = ['python3', 'detect_repo.py', '--src_dir', tmp_dir]
|
| 102 |
+
|
| 103 |
+
if commit:
|
| 104 |
+
command += ['--example_commit', commit]
|
| 105 |
+
else:
|
| 106 |
+
command += ['--repo_name', repo_name]
|
| 107 |
+
|
| 108 |
+
out, _ = detect_repo.execute(command,
|
| 109 |
+
location=os.path.dirname(
|
| 110 |
+
os.path.realpath(__file__)))
|
| 111 |
+
match = re.search(r'\bDetected repo: ([^ ]+) ([^ ]+)', out.rstrip())
|
| 112 |
+
if match and match.group(1) and match.group(2):
|
| 113 |
+
self.assertEqual(match.group(1), repo_origin)
|
| 114 |
+
self.assertEqual(match.group(2), os.path.join(tmp_dir, repo_name))
|
| 115 |
+
else:
|
| 116 |
+
self.assertIsNone(repo_origin)
|
| 117 |
+
self.assertIsNone(repo_name)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
if __name__ == '__main__':
|
| 121 |
+
unittest.main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_deps.sh
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# Install base-builder's dependencies in a architecture-aware way.
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
case $(uname -m) in
|
| 22 |
+
x86_64)
|
| 23 |
+
dpkg --add-architecture i386
|
| 24 |
+
;;
|
| 25 |
+
esac
|
| 26 |
+
|
| 27 |
+
apt-get update && \
|
| 28 |
+
apt-get install -y \
|
| 29 |
+
binutils-dev \
|
| 30 |
+
build-essential \
|
| 31 |
+
curl \
|
| 32 |
+
wget \
|
| 33 |
+
git \
|
| 34 |
+
jq \
|
| 35 |
+
patchelf \
|
| 36 |
+
rsync \
|
| 37 |
+
subversion \
|
| 38 |
+
zip
|
| 39 |
+
|
| 40 |
+
case $(uname -m) in
|
| 41 |
+
x86_64)
|
| 42 |
+
apt-get install -y libc6-dev-i386
|
| 43 |
+
;;
|
| 44 |
+
esac
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_java.sh
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# Install OpenJDK 17 and trim its size by removing unused components. This enables using Jazzer's mutation framework.
|
| 19 |
+
cd /tmp
|
| 20 |
+
curl --silent -L -O https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz && \
|
| 21 |
+
mkdir -p $JAVA_HOME
|
| 22 |
+
tar -xz --strip-components=1 -f openjdk-17.0.2_linux-x64_bin.tar.gz --directory $JAVA_HOME && \
|
| 23 |
+
rm -f openjdk-17.0.2_linux-x64_bin.tar.gz
|
| 24 |
+
rm -rf $JAVA_HOME/jmods $JAVA_HOME/lib/src.zip
|
| 25 |
+
|
| 26 |
+
# Install OpenJDK 15 and trim its size by removing unused components. Some projects only run with Java 15.
|
| 27 |
+
curl --silent -L -O https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-x64_bin.tar.gz && \
|
| 28 |
+
mkdir -p $JAVA_15_HOME
|
| 29 |
+
tar -xz --strip-components=1 -f openjdk-15.0.2_linux-x64_bin.tar.gz --directory $JAVA_15_HOME && \
|
| 30 |
+
rm -f openjdk-15.0.2_linux-x64_bin.tar.gz
|
| 31 |
+
rm -rf $JAVA_15_HOME/jmods $JAVA_15_HOME/lib/src.zip
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_javascript.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
# see installation instructions: https://github.com/nodesource/distributions#available-architectures
|
| 18 |
+
apt-get update
|
| 19 |
+
apt-get install -y ca-certificates curl gnupg
|
| 20 |
+
mkdir -p /etc/apt/keyrings
|
| 21 |
+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
| 22 |
+
|
| 23 |
+
NODE_MAJOR=20
|
| 24 |
+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
|
| 25 |
+
|
| 26 |
+
apt-get update
|
| 27 |
+
apt-get install nodejs -y
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_python.sh
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo "ATHERIS INSTALL"
|
| 19 |
+
unset CFLAGS CXXFLAGS
|
| 20 |
+
# PYI_STATIC_ZLIB=1 is needed for installing pyinstaller 5.0
|
| 21 |
+
export PYI_STATIC_ZLIB=1
|
| 22 |
+
LIBFUZZER_LIB=$( echo /usr/local/lib/clang/*/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer_no_main.a ) pip3 install -v --no-cache-dir "atheris>=2.3.0" "pyinstaller==6.10.0" "setuptools==72.1.0" "coverage==6.3.2"
|
| 23 |
+
rm -rf /tmp/*
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/install_swift.sh
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2021 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
SWIFT_PACKAGES="wget \
|
| 20 |
+
binutils \
|
| 21 |
+
git \
|
| 22 |
+
gnupg2 \
|
| 23 |
+
libc6-dev \
|
| 24 |
+
libcurl4 \
|
| 25 |
+
libedit2 \
|
| 26 |
+
libgcc-9-dev \
|
| 27 |
+
libpython2.7 \
|
| 28 |
+
libsqlite3-0 \
|
| 29 |
+
libstdc++-9-dev \
|
| 30 |
+
libxml2 \
|
| 31 |
+
libz3-dev \
|
| 32 |
+
pkg-config \
|
| 33 |
+
tzdata \
|
| 34 |
+
zlib1g-dev"
|
| 35 |
+
SWIFT_SYMBOLIZER_PACKAGES="build-essential make cmake ninja-build git python3 g++-multilib binutils-dev zlib1g-dev"
|
| 36 |
+
apt-get update && apt install -y $SWIFT_PACKAGES && \
|
| 37 |
+
apt install -y $SWIFT_SYMBOLIZER_PACKAGES --no-install-recommends
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
wget -q https://download.swift.org/swift-5.10.1-release/ubuntu2004/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-ubuntu20.04.tar.gz
|
| 41 |
+
tar xzf swift-5.10.1-RELEASE-ubuntu20.04.tar.gz
|
| 42 |
+
cp -r swift-5.10.1-RELEASE-ubuntu20.04/usr/* /usr/
|
| 43 |
+
rm -rf swift-5.10.1-RELEASE-ubuntu20.04.tar.gz swift-5.10.1-RELEASE-ubuntu20.04/
|
| 44 |
+
# TODO: Move to a seperate work dir
|
| 45 |
+
git clone https://github.com/llvm/llvm-project.git
|
| 46 |
+
cd llvm-project
|
| 47 |
+
git checkout 63bf228450b8403e0c5e828d276be47ffbcd00d0 # TODO: Keep in sync with base-clang.
|
| 48 |
+
git apply ../llvmsymbol.diff --verbose
|
| 49 |
+
cmake -G "Ninja" \
|
| 50 |
+
-DLIBCXX_ENABLE_SHARED=OFF \
|
| 51 |
+
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
|
| 52 |
+
-DLIBCXXABI_ENABLE_SHARED=OFF \
|
| 53 |
+
-DCMAKE_BUILD_TYPE=Release \
|
| 54 |
+
-DLLVM_TARGETS_TO_BUILD=X86 \
|
| 55 |
+
-DCMAKE_C_COMPILER=clang \
|
| 56 |
+
-DCMAKE_CXX_COMPILER=clang++ \
|
| 57 |
+
-DLLVM_BUILD_TESTS=OFF \
|
| 58 |
+
-DLLVM_INCLUDE_TESTS=OFF llvm
|
| 59 |
+
ninja -j$(nproc) llvm-symbolizer
|
| 60 |
+
cp bin/llvm-symbolizer /usr/local/bin/llvm-symbolizer-swift
|
| 61 |
+
|
| 62 |
+
cd $SRC
|
| 63 |
+
rm -rf llvm-project llvmsymbol.diff
|
| 64 |
+
|
| 65 |
+
# TODO: Cleanup packages
|
| 66 |
+
apt-get remove --purge -y wget zlib1g-dev
|
| 67 |
+
apt-get autoremove -y
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/cpp.cc
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
#include "header.h"
|
| 16 |
+
int main() {
|
| 17 |
+
return 0;
|
| 18 |
+
}
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/llvmsymbol.diff
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/llvm/lib/DebugInfo/Symbolize/CMakeLists.txt b/llvm/lib/DebugInfo/Symbolize/CMakeLists.txt
|
| 2 |
+
index acfb3bd0e..a499ee2e0 100644
|
| 3 |
+
--- a/llvm/lib/DebugInfo/Symbolize/CMakeLists.txt
|
| 4 |
+
+++ b/llvm/lib/DebugInfo/Symbolize/CMakeLists.txt
|
| 5 |
+
@@ -12,4 +12,11 @@ add_llvm_component_library(LLVMSymbolize
|
| 6 |
+
Object
|
| 7 |
+
Support
|
| 8 |
+
Demangle
|
| 9 |
+
- )
|
| 10 |
+
+
|
| 11 |
+
+ LINK_LIBS
|
| 12 |
+
+ /usr/lib/swift_static/linux/libswiftCore.a
|
| 13 |
+
+ /usr/lib/swift_static/linux/libicui18nswift.a
|
| 14 |
+
+ /usr/lib/swift_static/linux/libicuucswift.a
|
| 15 |
+
+ /usr/lib/swift_static/linux/libicudataswift.a
|
| 16 |
+
+ /usr/lib/x86_64-linux-gnu/libstdc++.so.6
|
| 17 |
+
+)
|
| 18 |
+
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
|
| 19 |
+
index fb4875f79..0030769ee 100644
|
| 20 |
+
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
|
| 21 |
+
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
|
| 22 |
+
@@ -36,6 +36,13 @@
|
| 23 |
+
#include <cassert>
|
| 24 |
+
#include <cstring>
|
| 25 |
+
|
| 26 |
+
+
|
| 27 |
+
+extern "C" char *swift_demangle(const char *mangledName,
|
| 28 |
+
+ size_t mangledNameLength,
|
| 29 |
+
+ char *outputBuffer,
|
| 30 |
+
+ size_t *outputBufferSize,
|
| 31 |
+
+ uint32_t flags);
|
| 32 |
+
+
|
| 33 |
+
namespace llvm {
|
| 34 |
+
namespace symbolize {
|
| 35 |
+
|
| 36 |
+
@@ -678,6 +685,14 @@ LLVMSymbolizer::DemangleName(const std::string &Name,
|
| 37 |
+
free(DemangledName);
|
| 38 |
+
return Result;
|
| 39 |
+
}
|
| 40 |
+
+ if (!Name.empty() && Name.front() == '$') {
|
| 41 |
+
+ char *DemangledName = swift_demangle(Name.c_str(), Name.length(), 0, 0, 0);
|
| 42 |
+
+ if (DemangledName) {
|
| 43 |
+
+ std::string Result = DemangledName;
|
| 44 |
+
+ free(DemangledName);
|
| 45 |
+
+ return Result;
|
| 46 |
+
+ }
|
| 47 |
+
+ }
|
| 48 |
+
|
| 49 |
+
if (DbiModuleDescriptor && DbiModuleDescriptor->isWin32Module())
|
| 50 |
+
return std::string(demanglePE32ExternCFunc(Name));
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/ossfuzz_coverage_runner.go
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package mypackagebeingfuzzed
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"io/ioutil"
|
| 19 |
+
"os"
|
| 20 |
+
"runtime/pprof"
|
| 21 |
+
"testing"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
func TestFuzzCorpus(t *testing.T) {
|
| 25 |
+
dir := os.Getenv("FUZZ_CORPUS_DIR")
|
| 26 |
+
if dir == "" {
|
| 27 |
+
t.Logf("No fuzzing corpus directory set")
|
| 28 |
+
return
|
| 29 |
+
}
|
| 30 |
+
infos, err := ioutil.ReadDir(dir)
|
| 31 |
+
if err != nil {
|
| 32 |
+
t.Logf("Not fuzzing corpus directory %s", err)
|
| 33 |
+
return
|
| 34 |
+
}
|
| 35 |
+
filename := ""
|
| 36 |
+
defer func() {
|
| 37 |
+
if r := recover(); r != nil {
|
| 38 |
+
t.Error("Fuzz panicked in "+filename, r)
|
| 39 |
+
}
|
| 40 |
+
}()
|
| 41 |
+
profname := os.Getenv("FUZZ_PROFILE_NAME")
|
| 42 |
+
if profname != "" {
|
| 43 |
+
f, err := os.Create(profname + ".cpu.prof")
|
| 44 |
+
if err != nil {
|
| 45 |
+
t.Logf("error creating profile file %s\n", err)
|
| 46 |
+
} else {
|
| 47 |
+
_ = pprof.StartCPUProfile(f)
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
for i := range infos {
|
| 51 |
+
filename = dir + infos[i].Name()
|
| 52 |
+
data, err := ioutil.ReadFile(filename)
|
| 53 |
+
if err != nil {
|
| 54 |
+
t.Error("Failed to read corpus file", err)
|
| 55 |
+
}
|
| 56 |
+
FuzzFunction(data)
|
| 57 |
+
}
|
| 58 |
+
if profname != "" {
|
| 59 |
+
pprof.StopCPUProfile()
|
| 60 |
+
f, err := os.Create(profname + ".heap.prof")
|
| 61 |
+
if err != nil {
|
| 62 |
+
t.Logf("error creating heap profile file %s\n", err)
|
| 63 |
+
}
|
| 64 |
+
if err = pprof.WriteHeapProfile(f); err != nil {
|
| 65 |
+
t.Logf("error writing heap profile file %s\n", err)
|
| 66 |
+
}
|
| 67 |
+
f.Close()
|
| 68 |
+
}
|
| 69 |
+
}
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/precompile_centipede
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
echo -n "Precompiling centipede"
|
| 19 |
+
|
| 20 |
+
# Build Centipede with bazel.
|
| 21 |
+
cd "$SRC/fuzztest/centipede/"
|
| 22 |
+
apt-get update && apt-get install libssl-dev -y
|
| 23 |
+
unset CXXFLAGS CFLAGS
|
| 24 |
+
# We need to use an older version of BAZEL because fuzztest relies on WORKSPACE
|
| 25 |
+
# Ref: https://github.com/google/oss-fuzz/pull/12838#issue-2733821058
|
| 26 |
+
export USE_BAZEL_VERSION=7.4.0
|
| 27 |
+
echo 'build --cxxopt=-stdlib=libc++ --linkopt=-lc++' >> /tmp/centipede.bazelrc
|
| 28 |
+
bazel --bazelrc=/tmp/centipede.bazelrc build -c opt :all
|
| 29 |
+
unset USE_BAZEL_VERSION
|
| 30 |
+
|
| 31 |
+
# Prepare the weak symbols:
|
| 32 |
+
# This is necessary because we compile the target binary and the intermediate
|
| 33 |
+
# auxiliary binaries with the same cflags. The auxiliary binaries do not need
|
| 34 |
+
# data-flow tracing flags, but will still throw errors when they cannot find
|
| 35 |
+
# the corresponding functions.
|
| 36 |
+
# The weak symbols provides fake implementations for intermediate binaries.
|
| 37 |
+
$CXX "$SRC/fuzztest/centipede/weak_sancov_stubs.cc" -c -o "$SRC/fuzztest/centipede/weak.o"
|
| 38 |
+
|
| 39 |
+
echo 'Removing extra stuff leftover to avoid bloating image.'
|
| 40 |
+
|
| 41 |
+
rm -rf /clang-*.tgz /clang
|
| 42 |
+
|
| 43 |
+
BAZEL_BIN_REAL_DIR=$(readlink -f $CENTIPEDE_BIN_DIR)
|
| 44 |
+
rm -rf $CENTIPEDE_BIN_DIR
|
| 45 |
+
mkdir -p $CENTIPEDE_BIN_DIR
|
| 46 |
+
mv $BAZEL_BIN_REAL_DIR/centipede/{centipede,libcentipede_runner.pic.a} $CENTIPEDE_BIN_DIR
|
| 47 |
+
rm -rf /root/.cache
|
| 48 |
+
|
| 49 |
+
echo 'Done.'
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/precompile_honggfuzz
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 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 |
+
|
| 18 |
+
echo "Precompiling honggfuzz"
|
| 19 |
+
export BUILD_OSSFUZZ_STATIC=true
|
| 20 |
+
|
| 21 |
+
PACKAGES=(
|
| 22 |
+
libunwind8-dev
|
| 23 |
+
libblocksruntime-dev
|
| 24 |
+
liblzma-dev
|
| 25 |
+
libiberty-dev
|
| 26 |
+
zlib1g-dev
|
| 27 |
+
pkg-config)
|
| 28 |
+
|
| 29 |
+
apt-get update && apt-get install -y ${PACKAGES[@]}
|
| 30 |
+
|
| 31 |
+
pushd $SRC/honggfuzz > /dev/null
|
| 32 |
+
make clean
|
| 33 |
+
# These CFLAGs match honggfuzz's default, with the exception of -mtune to
|
| 34 |
+
# improve portability and `-D_HF_LINUX_NO_BFD` to remove assembly instructions
|
| 35 |
+
# from the filenames.
|
| 36 |
+
CC=clang CFLAGS="-O3 -funroll-loops -D_HF_LINUX_NO_BFD" make
|
| 37 |
+
|
| 38 |
+
# libhfuzz.a will be added by CC/CXX linker directly during linking,
|
| 39 |
+
# but it's defined here to satisfy the build infrastructure
|
| 40 |
+
ar rcs honggfuzz.a libhfuzz/*.o libhfcommon/*.o
|
| 41 |
+
popd > /dev/null
|
| 42 |
+
|
| 43 |
+
apt-get remove -y --purge ${PACKAGES[@]}
|
| 44 |
+
apt-get autoremove -y
|
| 45 |
+
echo "Done."
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dist
|
| 2 |
+
pysecsan.egg-info*
|
| 3 |
+
build
|
| 4 |
+
.venv
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/redos.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 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 |
+
"""Sanitizer for regular expression dos."""
|
| 17 |
+
|
| 18 |
+
# pylint: disable=protected-access
|
| 19 |
+
|
| 20 |
+
import time
|
| 21 |
+
import os
|
| 22 |
+
from pysecsan import sanlib
|
| 23 |
+
|
| 24 |
+
START_RE_TIME = None
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# Hooks for regular expressions.
|
| 28 |
+
# Main problem is to identify ReDOS attemps. This is a non-trivial task
|
| 29 |
+
# - https://arxiv.org/pdf/1701.04045.pdf
|
| 30 |
+
# - https://dl.acm.org/doi/pdf/10.1145/3236024.3236027
|
| 31 |
+
# and the current approach we use is simply check for extensive computing time.
|
| 32 |
+
# In essence, this is more of a refinement of traditional timeout checker from
|
| 33 |
+
# the fuzzer, which, effectively will detect these types of attacks by way of
|
| 34 |
+
# timeouts.
|
| 35 |
+
#
|
| 36 |
+
# Perhaps the smartest would be to use something like e.g.
|
| 37 |
+
# https://github.com/doyensec/regexploit to scan the regex patterns.
|
| 38 |
+
# Other heuristics without going too technical on identifying super-linear
|
| 39 |
+
# regexes:
|
| 40 |
+
# - check
|
| 41 |
+
# - if 'taint' exists in re.compile(xx)
|
| 42 |
+
# - check
|
| 43 |
+
# - for backtracking possbility in PATTERN within re.comile(PATTERN)
|
| 44 |
+
# - and
|
| 45 |
+
# - 'taint' in findall(XX) calls.
|
| 46 |
+
# pylint: disable=global-statement
|
| 47 |
+
def hook_post_exec_re_pattern_findall(self, re_str):
|
| 48 |
+
"""Hook post exeution re.compile().findall()."""
|
| 49 |
+
_ = self # Satisfy lint
|
| 50 |
+
global START_RE_TIME
|
| 51 |
+
try:
|
| 52 |
+
endtime = time.time() - START_RE_TIME
|
| 53 |
+
if endtime > 4:
|
| 54 |
+
sanlib.abort_with_issue(f'Potential ReDOS attack.\n {re_str}', 'ReDOS')
|
| 55 |
+
except NameError:
|
| 56 |
+
sanlib.sanitizer_log(
|
| 57 |
+
'starttime is not set, which it should have. Error in PySecSan',
|
| 58 |
+
sanlib.LOG_INFO)
|
| 59 |
+
os._exit(1)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def hook_pre_exec_re_pattern_findall(self, string):
|
| 63 |
+
"""Hook pre execution of re.pattern().findall()."""
|
| 64 |
+
_ = (self, string) # Satisfy lint
|
| 65 |
+
global START_RE_TIME
|
| 66 |
+
START_RE_TIME = time.time()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def hook_post_exec_re_compile(retval, pattern, flags=None):
|
| 70 |
+
"""Hook for re.compile post execution to hook returned objects functions."""
|
| 71 |
+
_ = (pattern, flags) # Satisfy lint
|
| 72 |
+
sanlib.sanitizer_log('Inside of post compile hook', sanlib.LOG_DEBUG)
|
| 73 |
+
wrapper_object = sanlib.create_object_wrapper(
|
| 74 |
+
findall=(hook_pre_exec_re_pattern_findall,
|
| 75 |
+
hook_post_exec_re_pattern_findall))
|
| 76 |
+
hooked_object = wrapper_object(retval)
|
| 77 |
+
return hooked_object
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def hook_pre_exec_re_compile(pattern, flags=None):
|
| 81 |
+
"""Check if tainted input exists in pattern. If so, likely chance of making
|
| 82 |
+
ReDOS possible."""
|
| 83 |
+
_ = (pattern, flags) # Satisfy lint
|
| 84 |
+
sanlib.sanitizer_log('Inside re compile hook', sanlib.LOG_DEBUG)
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/setup.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2022 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 |
+
"""Config for installing python as package."""
|
| 15 |
+
from setuptools import setup, find_packages
|
| 16 |
+
|
| 17 |
+
setup(name='pysecsan',
|
| 18 |
+
version='0.1',
|
| 19 |
+
author='David Korczynski',
|
| 20 |
+
author_email='david@adalogics.com',
|
| 21 |
+
packages=find_packages(exclude='tests'))
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Tests including Proof of Exploits
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/eval_command_injection.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 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 |
+
"""Fuzzer targetting command injection of eval."""
|
| 16 |
+
# pylint: disable=eval-used
|
| 17 |
+
|
| 18 |
+
import sys
|
| 19 |
+
import atheris
|
| 20 |
+
import pysecsan
|
| 21 |
+
|
| 22 |
+
pysecsan.add_hooks()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def list_files_perhaps(param, magicval):
|
| 26 |
+
"""Pass fuzzer data into eval."""
|
| 27 |
+
if len(param) < 3:
|
| 28 |
+
return
|
| 29 |
+
if magicval == 1337:
|
| 30 |
+
try:
|
| 31 |
+
eval("FROMFUZZ")
|
| 32 |
+
except ValueError:
|
| 33 |
+
pass
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_one_input(data):
|
| 37 |
+
"""Fuzzer entrypoint."""
|
| 38 |
+
fdp = atheris.FuzzedDataProvider(data)
|
| 39 |
+
list_files_perhaps(fdp.ConsumeUnicodeNoSurrogates(24),
|
| 40 |
+
fdp.ConsumeIntInRange(500, 1500))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def main():
|
| 44 |
+
"""Set up and start fuzzing."""
|
| 45 |
+
|
| 46 |
+
atheris.instrument_all()
|
| 47 |
+
atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
|
| 48 |
+
atheris.Fuzz()
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == '__main__':
|
| 52 |
+
main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/ansible-runner-cve-2021-4041/fuzz_ansible_runner.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 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 |
+
"""Targets: https://github.com/advisories/GHSA-6j58-grhv-2769."""
|
| 16 |
+
|
| 17 |
+
import sys
|
| 18 |
+
import atheris
|
| 19 |
+
import pexpect
|
| 20 |
+
import pysecsan
|
| 21 |
+
import ansible_runner
|
| 22 |
+
from ansible_runner.config.runner import RunnerConfig
|
| 23 |
+
|
| 24 |
+
pysecsan.add_hooks()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_one_input(data):
|
| 28 |
+
"""Fuzzer entrypoint."""
|
| 29 |
+
fdp = atheris.FuzzedDataProvider(data)
|
| 30 |
+
|
| 31 |
+
conf = RunnerConfig('/tmp/')
|
| 32 |
+
conf.suppress_ansible_output = True
|
| 33 |
+
conf.expect_passwords = {pexpect.TIMEOUT: None, pexpect.EOF: None}
|
| 34 |
+
conf.cwd = str('/tmp/')
|
| 35 |
+
conf.env = {}
|
| 36 |
+
conf.job_timeout = 10
|
| 37 |
+
conf.idle_timeout = 0
|
| 38 |
+
conf.pexpect_timeout = 2.
|
| 39 |
+
conf.pexpect_use_poll = True
|
| 40 |
+
conf.command = 'from_fuzzer'
|
| 41 |
+
|
| 42 |
+
runner = ansible_runner.Runner(conf)
|
| 43 |
+
runner.resource_profiling = True
|
| 44 |
+
# rc.resource_profiling_base_cgroup = "; exec-san"
|
| 45 |
+
assistance = True
|
| 46 |
+
if assistance and fdp.ConsumeIntInRange(1, 100) > 80:
|
| 47 |
+
conf.resource_profiling_base_cgroup = 'FROMFUZZ'
|
| 48 |
+
else:
|
| 49 |
+
conf.resource_profiling_base_cgroup = fdp.ConsumeUnicodeNoSurrogates(24)
|
| 50 |
+
try:
|
| 51 |
+
runner.run()
|
| 52 |
+
except (RuntimeError, ValueError, TypeError) as _:
|
| 53 |
+
pass
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def main():
|
| 57 |
+
"""Set up and start fuzzing."""
|
| 58 |
+
atheris.instrument_all()
|
| 59 |
+
atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
|
| 60 |
+
atheris.Fuzz()
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
if __name__ == '__main__':
|
| 64 |
+
main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/libvcs-cve-2022-21187/build.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
python3 -m pip install pysecsan
|
| 19 |
+
|
| 20 |
+
python3 -m pip install libvcs==0.11.0
|
| 21 |
+
python3 ./fuzz_libvcs.py
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/libvcs-cve-2022-21187/fuzz_libvcs.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 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 |
+
"""Targets https://github.com/advisories/GHSA-mv2w-4jqc-6fg4."""
|
| 16 |
+
|
| 17 |
+
import sys
|
| 18 |
+
import atheris
|
| 19 |
+
import pysecsan
|
| 20 |
+
from libvcs.shortcuts import create_repo
|
| 21 |
+
|
| 22 |
+
pysecsan.add_hooks()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_one_input(data):
|
| 26 |
+
"""Target code injection in libvcs."""
|
| 27 |
+
fdp = atheris.FuzzedDataProvider(data)
|
| 28 |
+
mercurial_repo = create_repo(url=fdp.ConsumeUnicodeNoSurrogates(128),
|
| 29 |
+
vcs='hg',
|
| 30 |
+
repo_dir='./')
|
| 31 |
+
try:
|
| 32 |
+
mercurial_repo.update_repo()
|
| 33 |
+
except (ValueError, FileNotFoundError) as exception:
|
| 34 |
+
_ = exception # Satisfy lint
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def main():
|
| 38 |
+
"""Set up and start fuzzing."""
|
| 39 |
+
atheris.instrument_all()
|
| 40 |
+
atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
|
| 41 |
+
atheris.Fuzz()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == '__main__':
|
| 45 |
+
main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/python-ldap-GHSL-2021-117/build.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
python3 -m pip install pysecsan
|
| 19 |
+
|
| 20 |
+
git clone https://github.com/python-ldap/python-ldap
|
| 21 |
+
cd python-ldap
|
| 22 |
+
git checkout 404c36b702c5b3a7e60729745c8bda16098b1472
|
| 23 |
+
python3 -m pip install .
|
| 24 |
+
cd ../
|
| 25 |
+
python3 ./fuzz_ldap.py
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/build.sh
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
# Copyright 2022 Google LLC
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
git clone --depth 1 --branch 1.5.10 https://github.com/PyTorchLightning/pytorch-lightning.git
|
| 19 |
+
cd pytorch-lightning
|
| 20 |
+
python3 -m pip install .
|
| 21 |
+
cd ../
|
| 22 |
+
python3 ./fuzz_pytorch_lightning.py
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/poe/pytorch-lightning-1.5.10/fuzz_pytorch_lightning.dict
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"os.system('exec-sanitizer')"
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/yaml_deserialization_general.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 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 |
+
"""Fuzzer for insecure yaml deserialization."""
|
| 16 |
+
|
| 17 |
+
import sys
|
| 18 |
+
import yaml
|
| 19 |
+
import atheris
|
| 20 |
+
import pysecsan
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def serialize_with_tainted_data(param):
|
| 24 |
+
"""Hit insecure yaml function."""
|
| 25 |
+
try:
|
| 26 |
+
yaml.load(param, yaml.Loader)
|
| 27 |
+
except yaml.YAMLError:
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_one_input(data):
|
| 32 |
+
"""Fuzzer routine."""
|
| 33 |
+
fdp = atheris.FuzzedDataProvider(data)
|
| 34 |
+
serialize_with_tainted_data(fdp.ConsumeUnicodeNoSurrogates(32))
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def main():
|
| 38 |
+
"""Set up and start fuzzing."""
|
| 39 |
+
pysecsan.add_hooks()
|
| 40 |
+
|
| 41 |
+
atheris.instrument_all()
|
| 42 |
+
atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
|
| 43 |
+
atheris.Fuzz()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
if __name__ == '__main__':
|
| 47 |
+
main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/yaml_deserialization_simple.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/python3
|
| 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 |
+
"""Fuzzer triggering insecure yaml serialization."""
|
| 16 |
+
|
| 17 |
+
import sys
|
| 18 |
+
import yaml
|
| 19 |
+
import atheris
|
| 20 |
+
import pysecsan
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def serialize_with_tainted_data(param, magicval):
|
| 24 |
+
"""Pass data to insecure yaml functions."""
|
| 25 |
+
if magicval == 1337:
|
| 26 |
+
try:
|
| 27 |
+
yaml.load(param, yaml.Loader)
|
| 28 |
+
except yaml.YAMLError:
|
| 29 |
+
pass
|
| 30 |
+
elif magicval == 1338:
|
| 31 |
+
try:
|
| 32 |
+
yaml.load('FROMFUZZ', yaml.Loader)
|
| 33 |
+
except yaml.YAMLError:
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_one_input(data):
|
| 38 |
+
"""Fuzzer entrypoint."""
|
| 39 |
+
fdp = atheris.FuzzedDataProvider(data)
|
| 40 |
+
serialize_with_tainted_data(fdp.ConsumeUnicodeNoSurrogates(32),
|
| 41 |
+
fdp.ConsumeIntInRange(500, 1500))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
"""Set up and start fuzzing."""
|
| 46 |
+
pysecsan.add_hooks()
|
| 47 |
+
|
| 48 |
+
atheris.instrument_all()
|
| 49 |
+
atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
|
| 50 |
+
atheris.Fuzz()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
if __name__ == '__main__':
|
| 54 |
+
main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/srcmap
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eux
|
| 2 |
+
# Copyright 2016 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# Deterimine srcmap of checked out source code
|
| 19 |
+
|
| 20 |
+
SRCMAP=$(tempfile)
|
| 21 |
+
echo "{}" > $SRCMAP
|
| 22 |
+
|
| 23 |
+
# $1 - json file, $2 - jq program
|
| 24 |
+
function jq_inplace() {
|
| 25 |
+
F=$(tempfile) && cat $1 | jq "$2" > $F && mv $F $1
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
PATHS_TO_SCAN="$SRC"
|
| 29 |
+
|
| 30 |
+
if [[ $FUZZING_LANGUAGE == "go" ]]; then
|
| 31 |
+
PATHS_TO_SCAN="$PATHS_TO_SCAN $GOPATH"
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
# Git
|
| 35 |
+
for DOT_GIT_DIR in $(find $PATHS_TO_SCAN -name ".git" -type d); do
|
| 36 |
+
GIT_DIR=$(dirname $DOT_GIT_DIR)
|
| 37 |
+
cd $GIT_DIR
|
| 38 |
+
GIT_URL=$(git config --get remote.origin.url)
|
| 39 |
+
GIT_REV=$(git rev-parse HEAD)
|
| 40 |
+
jq_inplace $SRCMAP ".\"$GIT_DIR\" = { type: \"git\", url: \"$GIT_URL\", rev: \"$GIT_REV\" }"
|
| 41 |
+
done
|
| 42 |
+
|
| 43 |
+
# Subversion
|
| 44 |
+
for DOT_SVN_DIR in $(find $PATHS_TO_SCAN -name ".svn" -type d); do
|
| 45 |
+
SVN_DIR=$(dirname $DOT_SVN_DIR)
|
| 46 |
+
cd $SVN_DIR
|
| 47 |
+
SVN_URL=$(svn info | grep "^URL:" | sed 's/URL: //g')
|
| 48 |
+
SVN_REV=$(svn info -r HEAD | grep "^Revision:" | sed 's/Revision: //g')
|
| 49 |
+
jq_inplace $SRCMAP ".\"$SVN_DIR\" = { type: \"svn\", url: \"$SVN_URL\", rev: \"$SVN_REV\" }"
|
| 50 |
+
done
|
| 51 |
+
|
| 52 |
+
# Mercurial
|
| 53 |
+
for DOT_HG_DIR in $(find $PATHS_TO_SCAN -name ".hg" -type d); do
|
| 54 |
+
HG_DIR=$(dirname $DOT_HG_DIR)
|
| 55 |
+
cd $HG_DIR
|
| 56 |
+
HG_URL=$(hg paths default)
|
| 57 |
+
HG_REV=$(hg --debug id -r. -i)
|
| 58 |
+
jq_inplace $SRCMAP ".\"$HG_DIR\" = { type: \"hg\", url: \"$HG_URL\", rev: \"$HG_REV\" }"
|
| 59 |
+
done
|
| 60 |
+
|
| 61 |
+
if [ "${OSSFUZZ_REVISION-}" != "" ]; then
|
| 62 |
+
jq_inplace $SRCMAP ".\"/src\" = { type: \"git\", url: \"https://github.com/google/oss-fuzz.git\", rev: \"$OSSFUZZ_REVISION\" }"
|
| 63 |
+
fi
|
| 64 |
+
|
| 65 |
+
cat $SRCMAP
|
| 66 |
+
rm $SRCMAP
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/test_data/culprit-commit.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ac9ee01fcbfac745aaedca0393a8e1c8a33acd8d is the first bad commit
|
| 2 |
+
commit ac9ee01fcbfac745aaedca0393a8e1c8a33acd8d
|
| 3 |
+
Author: John Doe <johndoe@example.com>
|
| 4 |
+
Date: Tue Aug 6 08:41:53 2019 +0000
|
| 5 |
+
|
| 6 |
+
[compiler-rt] Implement getrandom interception
|
| 7 |
+
|
| 8 |
+
Summary:
|
| 9 |
+
Straightforward implementation of `getrandom` syscall and libc
|
| 10 |
+
hooks.
|
| 11 |
+
|
| 12 |
+
Test Plan: Local MSAN failures caused by uninstrumented `getrandom`
|
| 13 |
+
calls stop failing.
|
| 14 |
+
|
| 15 |
+
Patch by John Doe 3.
|
| 16 |
+
|
| 17 |
+
Reviewers: jonhdoe2, johndoe
|
| 18 |
+
|
| 19 |
+
Reviewed By: johndoe
|
| 20 |
+
|
| 21 |
+
Subscribers: johndoe4, johndoe5, #sanitizers, llvm-commits
|
| 22 |
+
|
| 23 |
+
Tags: #sanitizers, #llvm
|
| 24 |
+
|
| 25 |
+
Differential Revision: https://reviews.llvm.org/D65551
|
| 26 |
+
|
| 27 |
+
llvm-svn: 367999
|
| 28 |
+
|
| 29 |
+
:040000 040000 8db10511ca83cc7b0265c7703684cd386350151b 62508fdc5e8919bbb2a0bd185cc109868192cdb0 M compiler-rt
|
| 30 |
+
bisect run success
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-builder/write_labels.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 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 |
+
"""Script for writing from project.yaml to .labels file."""
|
| 16 |
+
|
| 17 |
+
import os
|
| 18 |
+
import json
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def main():
|
| 23 |
+
"""Writes labels."""
|
| 24 |
+
if len(sys.argv) != 3:
|
| 25 |
+
print('Usage: write_labels.py labels_json out_dir', file=sys.stderr)
|
| 26 |
+
sys.exit(1)
|
| 27 |
+
|
| 28 |
+
labels_by_target = json.loads(sys.argv[1])
|
| 29 |
+
out = sys.argv[2]
|
| 30 |
+
|
| 31 |
+
for target_name, labels in labels_by_target.items():
|
| 32 |
+
# Skip over wildcard value applying to all fuzz targets
|
| 33 |
+
if target_name == '*':
|
| 34 |
+
continue
|
| 35 |
+
with open(os.path.join(out, target_name + '.labels'), 'w') as file_handle:
|
| 36 |
+
file_handle.write('\n'.join(labels))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
main()
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-clang/Dockerfile
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2016 Google Inc.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
#
|
| 15 |
+
################################################################################
|
| 16 |
+
|
| 17 |
+
# Docker image with clang installed.
|
| 18 |
+
|
| 19 |
+
ARG IMG_TAG=latest
|
| 20 |
+
FROM ghcr.io/aixcc-finals/base-image:${IMG_TAG}
|
| 21 |
+
|
| 22 |
+
ARG arch=x86_64
|
| 23 |
+
|
| 24 |
+
ENV FUZZINTRO_OUTDIR=$SRC
|
| 25 |
+
|
| 26 |
+
# Install newer cmake.
|
| 27 |
+
# Many projects, as well as recent clang versions, need a newer cmake.
|
| 28 |
+
ENV CMAKE_VERSION 3.29.2
|
| 29 |
+
RUN apt-get update && apt-get install -y wget sudo && \
|
| 30 |
+
wget -q https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-Linux-$arch.sh && \
|
| 31 |
+
chmod +x cmake-$CMAKE_VERSION-Linux-$arch.sh && \
|
| 32 |
+
./cmake-$CMAKE_VERSION-Linux-$arch.sh --skip-license --prefix="/usr/local" && \
|
| 33 |
+
rm cmake-$CMAKE_VERSION-Linux-$arch.sh && \
|
| 34 |
+
SUDO_FORCE_REMOVE=yes apt-get autoremove --purge -y wget sudo && \
|
| 35 |
+
rm -rf /usr/local/doc/cmake /usr/local/bin/cmake-gui
|
| 36 |
+
|
| 37 |
+
RUN apt-get update && apt-get install -y git && \
|
| 38 |
+
git clone https://github.com/ossf/fuzz-introspector.git fuzz-introspector && \
|
| 39 |
+
cd fuzz-introspector && \
|
| 40 |
+
git checkout f9bcb8824a18d60d57e2430c5b43f525d811cae8 && \
|
| 41 |
+
git submodule init && \
|
| 42 |
+
git submodule update && \
|
| 43 |
+
apt-get autoremove --purge -y git && \
|
| 44 |
+
rm -rf .git
|
| 45 |
+
|
| 46 |
+
COPY checkout_build_install_llvm.sh /root/
|
| 47 |
+
# Keep all steps in the same script to decrease the number of intermediate
|
| 48 |
+
# layes in docker file.
|
| 49 |
+
RUN /root/checkout_build_install_llvm.sh
|
| 50 |
+
RUN rm /root/checkout_build_install_llvm.sh
|
| 51 |
+
|
| 52 |
+
# Setup the environment.
|
| 53 |
+
ENV CC "clang"
|
| 54 |
+
ENV CXX "clang++"
|
| 55 |
+
ENV CCC "clang++"
|
| 56 |
+
|
| 57 |
+
# FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION is described at
|
| 58 |
+
# https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
|
| 59 |
+
|
| 60 |
+
# The implicit-function-declaration and implicit-int errors are downgraded to a
|
| 61 |
+
# warning, to allow compiling legacy code.
|
| 62 |
+
# See https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html#potentially-breaking-changes
|
| 63 |
+
# Same for deprecated-declarations, int-conversion,
|
| 64 |
+
# incompatible-function-pointer-types, enum-constexpr-conversion,
|
| 65 |
+
# vla-cxx-extension
|
| 66 |
+
|
| 67 |
+
ENV CFLAGS -O1 \
|
| 68 |
+
-fno-omit-frame-pointer \
|
| 69 |
+
-gline-tables-only \
|
| 70 |
+
-Wno-error=enum-constexpr-conversion \
|
| 71 |
+
-Wno-error=incompatible-function-pointer-types \
|
| 72 |
+
-Wno-error=int-conversion \
|
| 73 |
+
-Wno-error=deprecated-declarations \
|
| 74 |
+
-Wno-error=implicit-function-declaration \
|
| 75 |
+
-Wno-error=implicit-int \
|
| 76 |
+
-Wno-error=vla-cxx-extension \
|
| 77 |
+
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
| 78 |
+
ENV CXXFLAGS_EXTRA "-stdlib=libc++"
|
| 79 |
+
ENV CXXFLAGS "$CFLAGS $CXXFLAGS_EXTRA"
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/bad_build_check
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -u
|
| 2 |
+
# Copyright 2017 Google Inc.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
#
|
| 16 |
+
################################################################################
|
| 17 |
+
|
| 18 |
+
# A minimal number of runs to test fuzz target with a non-empty input.
|
| 19 |
+
MIN_NUMBER_OF_RUNS=4
|
| 20 |
+
|
| 21 |
+
# The "example" target has 73 with ASan, 65 with UBSan, and 6648 with MSan.
|
| 22 |
+
# Real world targets have greater values (arduinojson: 407, zlib: 664).
|
| 23 |
+
# Mercurial's bdiff_fuzzer has 116 PCs when built with ASan.
|
| 24 |
+
THRESHOLD_FOR_NUMBER_OF_EDGES=100
|
| 25 |
+
|
| 26 |
+
# A fuzz target is supposed to have at least two functions, such as
|
| 27 |
+
# LLVMFuzzerTestOneInput and an API that is being called from there.
|
| 28 |
+
THRESHOLD_FOR_NUMBER_OF_FUNCTIONS=2
|
| 29 |
+
|
| 30 |
+
# Threshold values for different sanitizers used by instrumentation checks.
|
| 31 |
+
ASAN_CALLS_THRESHOLD_FOR_ASAN_BUILD=1000
|
| 32 |
+
ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD=0
|
| 33 |
+
|
| 34 |
+
# The value below can definitely be higher (like 500-1000), but avoid being too
|
| 35 |
+
# agressive here while still evaluating the DFT-based fuzzing approach.
|
| 36 |
+
DFSAN_CALLS_THRESHOLD_FOR_DFSAN_BUILD=100
|
| 37 |
+
DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD=0
|
| 38 |
+
|
| 39 |
+
MSAN_CALLS_THRESHOLD_FOR_MSAN_BUILD=1000
|
| 40 |
+
# Some engines (e.g. honggfuzz) may make a very small number of calls to msan
|
| 41 |
+
# for memory poisoning.
|
| 42 |
+
MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD=3
|
| 43 |
+
|
| 44 |
+
# Usually, a non UBSan build (e.g. ASan) has 165 calls to UBSan runtime. The
|
| 45 |
+
# majority of targets built with UBSan have 200+ UBSan calls, but there are
|
| 46 |
+
# some very small targets that may have < 200 UBSan calls even in a UBSan build.
|
| 47 |
+
# Use the threshold value of 168 (slightly > 165) for UBSan build.
|
| 48 |
+
UBSAN_CALLS_THRESHOLD_FOR_UBSAN_BUILD=168
|
| 49 |
+
|
| 50 |
+
# It would be risky to use the threshold value close to 165 for non UBSan build,
|
| 51 |
+
# as UBSan runtime may change any time and thus we could have different number
|
| 52 |
+
# of calls to UBSan runtime even in ASan build. With that, we use the threshold
|
| 53 |
+
# value of 200 that would detect unnecessary UBSan instrumentation in the vast
|
| 54 |
+
# majority of targets, except of a handful very small ones, which would not be
|
| 55 |
+
# a big concern either way as the overhead for them would not be significant.
|
| 56 |
+
UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD=200
|
| 57 |
+
|
| 58 |
+
# ASan builds on i386 generally have about 250 UBSan runtime calls.
|
| 59 |
+
if [[ $ARCHITECTURE == 'i386' ]]
|
| 60 |
+
then
|
| 61 |
+
UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD=280
|
| 62 |
+
fi
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# Verify that the given fuzz target is correctly built to run with a particular
|
| 66 |
+
# engine.
|
| 67 |
+
function check_engine {
|
| 68 |
+
local FUZZER=$1
|
| 69 |
+
local FUZZER_NAME=$(basename $FUZZER)
|
| 70 |
+
local FUZZER_OUTPUT="/tmp/$FUZZER_NAME.output"
|
| 71 |
+
local CHECK_FAILED=0
|
| 72 |
+
|
| 73 |
+
if [[ "$FUZZING_ENGINE" == libfuzzer ]]; then
|
| 74 |
+
# Store fuzz target's output into a temp file to be used for further checks.
|
| 75 |
+
$FUZZER -seed=1337 -runs=$MIN_NUMBER_OF_RUNS &>$FUZZER_OUTPUT
|
| 76 |
+
CHECK_FAILED=$(egrep "ERROR: no interesting inputs were found. Is the code instrumented" -c $FUZZER_OUTPUT)
|
| 77 |
+
if (( $CHECK_FAILED > 0 )); then
|
| 78 |
+
echo "BAD BUILD: $FUZZER does not seem to have coverage instrumentation."
|
| 79 |
+
cat $FUZZER_OUTPUT
|
| 80 |
+
# Bail out as the further check does not make any sense, there are 0 PCs.
|
| 81 |
+
return 1
|
| 82 |
+
fi
|
| 83 |
+
|
| 84 |
+
local NUMBER_OF_EDGES=$(grep -Po "INFO: Loaded [[:digit:]]+ module.*\(.*(counters|guards)\):[[:space:]]+\K[[:digit:]]+" $FUZZER_OUTPUT)
|
| 85 |
+
|
| 86 |
+
# If a fuzz target fails to start, grep won't find anything, so bail out early to let check_startup_crash deal with it.
|
| 87 |
+
[[ -z "$NUMBER_OF_EDGES" ]] && return
|
| 88 |
+
|
| 89 |
+
if (( $NUMBER_OF_EDGES < $THRESHOLD_FOR_NUMBER_OF_EDGES )); then
|
| 90 |
+
echo "BAD BUILD: $FUZZER seems to have only partial coverage instrumentation."
|
| 91 |
+
fi
|
| 92 |
+
elif [[ "$FUZZING_ENGINE" == afl ]]; then
|
| 93 |
+
AFL_FORKSRV_INIT_TMOUT=30000 AFL_NO_UI=1 SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 35s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 94 |
+
CHECK_PASSED=$(egrep "All set and ready to roll" -c $FUZZER_OUTPUT)
|
| 95 |
+
if (( $CHECK_PASSED == 0 )); then
|
| 96 |
+
echo "BAD BUILD: fuzzing $FUZZER with afl-fuzz failed."
|
| 97 |
+
cat $FUZZER_OUTPUT
|
| 98 |
+
return 1
|
| 99 |
+
fi
|
| 100 |
+
elif [[ "$FUZZING_ENGINE" == honggfuzz ]]; then
|
| 101 |
+
SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 20s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 102 |
+
CHECK_PASSED=$(egrep "^Sz:[0-9]+ Tm:[0-9]+" -c $FUZZER_OUTPUT)
|
| 103 |
+
if (( $CHECK_PASSED == 0 )); then
|
| 104 |
+
echo "BAD BUILD: fuzzing $FUZZER with honggfuzz failed."
|
| 105 |
+
cat $FUZZER_OUTPUT
|
| 106 |
+
return 1
|
| 107 |
+
fi
|
| 108 |
+
elif [[ "$FUZZING_ENGINE" == dataflow ]]; then
|
| 109 |
+
$FUZZER &> $FUZZER_OUTPUT
|
| 110 |
+
local NUMBER_OF_FUNCTIONS=$(grep -Po "INFO:\s+\K[[:digit:]]+(?=\s+instrumented function.*)" $FUZZER_OUTPUT)
|
| 111 |
+
[[ -z "$NUMBER_OF_FUNCTIONS" ]] && NUMBER_OF_FUNCTIONS=0
|
| 112 |
+
if (( $NUMBER_OF_FUNCTIONS < $THRESHOLD_FOR_NUMBER_OF_FUNCTIONS )); then
|
| 113 |
+
echo "BAD BUILD: $FUZZER does not seem to be properly built in 'dataflow' config."
|
| 114 |
+
cat $FUZZER_OUTPUT
|
| 115 |
+
return 1
|
| 116 |
+
fi
|
| 117 |
+
elif [[ "$FUZZING_ENGINE" == centipede \
|
| 118 |
+
&& ("${HELPER:-}" == True || "$SANITIZER" == none ) ]]; then
|
| 119 |
+
# Performs run test on unsanitized binaries with auxiliary sanitized
|
| 120 |
+
# binaries if they are built with helper.py.
|
| 121 |
+
# Performs run test on unsanitized binaries without auxiliary sanitized
|
| 122 |
+
# binaries if they are from trial build and production build.
|
| 123 |
+
# TODO(Dongge): Support run test with sanitized binaries for trial and
|
| 124 |
+
# production build.
|
| 125 |
+
SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 20s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 126 |
+
CHECK_PASSED=$(egrep "\[S0.0] begin-fuzz: ft: 0 corp: 0/0" -c $FUZZER_OUTPUT)
|
| 127 |
+
if (( $CHECK_PASSED == 0 )); then
|
| 128 |
+
echo "BAD BUILD: fuzzing $FUZZER with centipede failed."
|
| 129 |
+
cat $FUZZER_OUTPUT
|
| 130 |
+
return 1
|
| 131 |
+
fi
|
| 132 |
+
fi
|
| 133 |
+
|
| 134 |
+
return 0
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
# Verify that the given fuzz target has been built properly and works.
|
| 138 |
+
function check_startup_crash {
|
| 139 |
+
local FUZZER=$1
|
| 140 |
+
local FUZZER_NAME=$(basename $FUZZER)
|
| 141 |
+
local FUZZER_OUTPUT="/tmp/$FUZZER_NAME.output"
|
| 142 |
+
local CHECK_PASSED=0
|
| 143 |
+
|
| 144 |
+
if [[ "$FUZZING_ENGINE" = libfuzzer ]]; then
|
| 145 |
+
# Skip seed corpus as there is another explicit check that uses seed corpora.
|
| 146 |
+
SKIP_SEED_CORPUS=1 run_fuzzer $FUZZER_NAME -seed=1337 -runs=$MIN_NUMBER_OF_RUNS &>$FUZZER_OUTPUT
|
| 147 |
+
CHECK_PASSED=$(egrep "Done $MIN_NUMBER_OF_RUNS runs" -c $FUZZER_OUTPUT)
|
| 148 |
+
elif [[ "$FUZZING_ENGINE" = afl ]]; then
|
| 149 |
+
AFL_FORKSRV_INIT_TMOUT=30000 AFL_NO_UI=1 SKIP_SEED_CORPUS=1 timeout --preserve-status -s INT 35s run_fuzzer $FUZZER_NAME &>$FUZZER_OUTPUT
|
| 150 |
+
if [ $(egrep "target binary (crashed|terminated)" -c $FUZZER_OUTPUT) -eq 0 ]; then
|
| 151 |
+
CHECK_PASSED=1
|
| 152 |
+
fi
|
| 153 |
+
elif [[ "$FUZZING_ENGINE" = dataflow ]]; then
|
| 154 |
+
# TODO(https://github.com/google/oss-fuzz/issues/1632): add check for
|
| 155 |
+
# binaries compiled with dataflow engine when the interface becomes stable.
|
| 156 |
+
CHECK_PASSED=1
|
| 157 |
+
else
|
| 158 |
+
# TODO: add checks for another fuzzing engines if possible.
|
| 159 |
+
CHECK_PASSED=1
|
| 160 |
+
fi
|
| 161 |
+
|
| 162 |
+
if [ "$CHECK_PASSED" -eq "0" ]; then
|
| 163 |
+
echo "BAD BUILD: $FUZZER seems to have either startup crash or exit:"
|
| 164 |
+
cat $FUZZER_OUTPUT
|
| 165 |
+
return 1
|
| 166 |
+
fi
|
| 167 |
+
|
| 168 |
+
return 0
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
# Mixed sanitizers check for ASan build.
|
| 172 |
+
function check_asan_build {
|
| 173 |
+
local FUZZER=$1
|
| 174 |
+
local ASAN_CALLS=$2
|
| 175 |
+
local DFSAN_CALLS=$3
|
| 176 |
+
local MSAN_CALLS=$4
|
| 177 |
+
local UBSAN_CALLS=$5
|
| 178 |
+
|
| 179 |
+
# Perform all the checks for more detailed error message.
|
| 180 |
+
if (( $ASAN_CALLS < $ASAN_CALLS_THRESHOLD_FOR_ASAN_BUILD )); then
|
| 181 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with ASan."
|
| 182 |
+
return 1
|
| 183 |
+
fi
|
| 184 |
+
|
| 185 |
+
if (( $DFSAN_CALLS > $DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD )); then
|
| 186 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with DFSan."
|
| 187 |
+
return 1
|
| 188 |
+
fi
|
| 189 |
+
|
| 190 |
+
if (( $MSAN_CALLS > $MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD )); then
|
| 191 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with MSan."
|
| 192 |
+
return 1
|
| 193 |
+
fi
|
| 194 |
+
|
| 195 |
+
if (( $UBSAN_CALLS > $UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD )); then
|
| 196 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with UBSan."
|
| 197 |
+
return 1
|
| 198 |
+
fi
|
| 199 |
+
|
| 200 |
+
return 0
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
# Mixed sanitizers check for DFSan build.
|
| 204 |
+
function check_dfsan_build {
|
| 205 |
+
local FUZZER=$1
|
| 206 |
+
local ASAN_CALLS=$2
|
| 207 |
+
local DFSAN_CALLS=$3
|
| 208 |
+
local MSAN_CALLS=$4
|
| 209 |
+
local UBSAN_CALLS=$5
|
| 210 |
+
|
| 211 |
+
# Perform all the checks for more detailed error message.
|
| 212 |
+
if (( $ASAN_CALLS > $ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD )); then
|
| 213 |
+
echo "BAD BUILD: DFSan build of $FUZZER seems to be compiled with ASan."
|
| 214 |
+
return 1
|
| 215 |
+
fi
|
| 216 |
+
|
| 217 |
+
if (( $DFSAN_CALLS < $DFSAN_CALLS_THRESHOLD_FOR_DFSAN_BUILD )); then
|
| 218 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with DFSan."
|
| 219 |
+
return 1
|
| 220 |
+
fi
|
| 221 |
+
|
| 222 |
+
if (( $MSAN_CALLS > $MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD )); then
|
| 223 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with MSan."
|
| 224 |
+
return 1
|
| 225 |
+
fi
|
| 226 |
+
|
| 227 |
+
if (( $UBSAN_CALLS > $UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD )); then
|
| 228 |
+
echo "BAD BUILD: ASan build of $FUZZER seems to be compiled with UBSan."
|
| 229 |
+
return 1
|
| 230 |
+
fi
|
| 231 |
+
|
| 232 |
+
return 0
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
# Mixed sanitizers check for MSan build.
|
| 237 |
+
function check_msan_build {
|
| 238 |
+
local FUZZER=$1
|
| 239 |
+
local ASAN_CALLS=$2
|
| 240 |
+
local DFSAN_CALLS=$3
|
| 241 |
+
local MSAN_CALLS=$4
|
| 242 |
+
local UBSAN_CALLS=$5
|
| 243 |
+
|
| 244 |
+
# Perform all the checks for more detailed error message.
|
| 245 |
+
if (( $ASAN_CALLS > $ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD )); then
|
| 246 |
+
echo "BAD BUILD: MSan build of $FUZZER seems to be compiled with ASan."
|
| 247 |
+
return 1
|
| 248 |
+
fi
|
| 249 |
+
|
| 250 |
+
if (( $DFSAN_CALLS > $DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD )); then
|
| 251 |
+
echo "BAD BUILD: MSan build of $FUZZER seems to be compiled with DFSan."
|
| 252 |
+
return 1
|
| 253 |
+
fi
|
| 254 |
+
|
| 255 |
+
if (( $MSAN_CALLS < $MSAN_CALLS_THRESHOLD_FOR_MSAN_BUILD )); then
|
| 256 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with MSan."
|
| 257 |
+
return 1
|
| 258 |
+
fi
|
| 259 |
+
|
| 260 |
+
if (( $UBSAN_CALLS > $UBSAN_CALLS_THRESHOLD_FOR_NON_UBSAN_BUILD )); then
|
| 261 |
+
echo "BAD BUILD: MSan build of $FUZZER seems to be compiled with UBSan."
|
| 262 |
+
return 1
|
| 263 |
+
fi
|
| 264 |
+
|
| 265 |
+
return 0
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
# Mixed sanitizers check for UBSan build.
|
| 269 |
+
function check_ubsan_build {
|
| 270 |
+
local FUZZER=$1
|
| 271 |
+
local ASAN_CALLS=$2
|
| 272 |
+
local DFSAN_CALLS=$3
|
| 273 |
+
local MSAN_CALLS=$4
|
| 274 |
+
local UBSAN_CALLS=$5
|
| 275 |
+
|
| 276 |
+
if [[ "$FUZZING_ENGINE" != libfuzzer ]]; then
|
| 277 |
+
# Ignore UBSan checks for fuzzing engines other than libFuzzer because:
|
| 278 |
+
# A) we (probably) are not going to use those with UBSan
|
| 279 |
+
# B) such builds show indistinguishable number of calls to UBSan
|
| 280 |
+
return 0
|
| 281 |
+
fi
|
| 282 |
+
|
| 283 |
+
# Perform all the checks for more detailed error message.
|
| 284 |
+
if (( $ASAN_CALLS > $ASAN_CALLS_THRESHOLD_FOR_NON_ASAN_BUILD )); then
|
| 285 |
+
echo "BAD BUILD: UBSan build of $FUZZER seems to be compiled with ASan."
|
| 286 |
+
return 1
|
| 287 |
+
fi
|
| 288 |
+
|
| 289 |
+
if (( $DFSAN_CALLS > $DFSAN_CALLS_THRESHOLD_FOR_NON_DFSAN_BUILD )); then
|
| 290 |
+
echo "BAD BUILD: UBSan build of $FUZZER seems to be compiled with DFSan."
|
| 291 |
+
return 1
|
| 292 |
+
fi
|
| 293 |
+
|
| 294 |
+
if (( $MSAN_CALLS > $MSAN_CALLS_THRESHOLD_FOR_NON_MSAN_BUILD )); then
|
| 295 |
+
echo "BAD BUILD: UBSan build of $FUZZER seems to be compiled with MSan."
|
| 296 |
+
return 1
|
| 297 |
+
fi
|
| 298 |
+
|
| 299 |
+
if (( $UBSAN_CALLS < $UBSAN_CALLS_THRESHOLD_FOR_UBSAN_BUILD )); then
|
| 300 |
+
echo "BAD BUILD: $FUZZER does not seem to be compiled with UBSan."
|
| 301 |
+
return 1
|
| 302 |
+
fi
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
# Verify that the given fuzz target is compiled with correct sanitizer.
|
| 306 |
+
function check_mixed_sanitizers {
|
| 307 |
+
local FUZZER=$1
|
| 308 |
+
local result=0
|
| 309 |
+
local CALL_INSN=
|
| 310 |
+
|
| 311 |
+
if [ "${FUZZING_LANGUAGE:-}" = "jvm" ]; then
|
| 312 |
+
# Sanitizer runtime is linked into the Jazzer driver, so this check does not
|
| 313 |
+
# apply.
|
| 314 |
+
return 0
|
| 315 |
+
fi
|
| 316 |
+
|
| 317 |
+
if [ "${FUZZING_LANGUAGE:-}" = "javascript" ]; then
|
| 318 |
+
# Jazzer.js currently does not support using sanitizers with native Node.js addons.
|
| 319 |
+
# This is not relevant anyways since supporting this will be done by preloading
|
| 320 |
+
# the sanitizers in the wrapper script starting Jazzer.js.
|
| 321 |
+
return 0
|
| 322 |
+
fi
|
| 323 |
+
|
| 324 |
+
if [ "${FUZZING_LANGUAGE:-}" = "python" ]; then
|
| 325 |
+
# Sanitizer runtime is loaded via LD_PRELOAD, so this check does not apply.
|
| 326 |
+
return 0
|
| 327 |
+
fi
|
| 328 |
+
|
| 329 |
+
# For fuzztest fuzzers point to the binary instead of launcher script.
|
| 330 |
+
if [[ $FUZZER == *"@"* ]]; then
|
| 331 |
+
FUZZER=(${FUZZER//@/ }[0])
|
| 332 |
+
fi
|
| 333 |
+
|
| 334 |
+
CALL_INSN=
|
| 335 |
+
if [[ $ARCHITECTURE == "x86_64" ]]
|
| 336 |
+
then
|
| 337 |
+
CALL_INSN="callq?\s+[0-9a-f]+\s+<"
|
| 338 |
+
elif [[ $ARCHITECTURE == "i386" ]]
|
| 339 |
+
then
|
| 340 |
+
CALL_INSN="call\s+[0-9a-f]+\s+<"
|
| 341 |
+
elif [[ $ARCHITECTURE == "aarch64" ]]
|
| 342 |
+
then
|
| 343 |
+
CALL_INSN="bl\s+[0-9a-f]+\s+<"
|
| 344 |
+
else
|
| 345 |
+
echo "UNSUPPORTED ARCHITECTURE"
|
| 346 |
+
exit 1
|
| 347 |
+
fi
|
| 348 |
+
local ASAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__asan" -c)
|
| 349 |
+
local DFSAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__dfsan" -c)
|
| 350 |
+
local MSAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__msan" -c)
|
| 351 |
+
local UBSAN_CALLS=$(objdump -dC $FUZZER | egrep "${CALL_INSN}__ubsan" -c)
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
if [[ "$SANITIZER" = address ]]; then
|
| 355 |
+
check_asan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 356 |
+
result=$?
|
| 357 |
+
elif [[ "$SANITIZER" = dataflow ]]; then
|
| 358 |
+
check_dfsan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 359 |
+
result=$?
|
| 360 |
+
elif [[ "$SANITIZER" = memory ]]; then
|
| 361 |
+
check_msan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 362 |
+
result=$?
|
| 363 |
+
elif [[ "$SANITIZER" = undefined ]]; then
|
| 364 |
+
check_ubsan_build $FUZZER $ASAN_CALLS $DFSAN_CALLS $MSAN_CALLS $UBSAN_CALLS
|
| 365 |
+
result=$?
|
| 366 |
+
elif [[ "$SANITIZER" = thread ]]; then
|
| 367 |
+
# TODO(metzman): Implement this.
|
| 368 |
+
result=0
|
| 369 |
+
fi
|
| 370 |
+
|
| 371 |
+
return $result
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
# Verify that the given fuzz target doesn't crash on the seed corpus.
|
| 375 |
+
function check_seed_corpus {
|
| 376 |
+
local FUZZER=$1
|
| 377 |
+
local FUZZER_NAME="$(basename $FUZZER)"
|
| 378 |
+
local FUZZER_OUTPUT="/tmp/$FUZZER_NAME.output"
|
| 379 |
+
|
| 380 |
+
if [[ "$FUZZING_ENGINE" != libfuzzer ]]; then
|
| 381 |
+
return 0
|
| 382 |
+
fi
|
| 383 |
+
|
| 384 |
+
# Set up common fuzzing arguments, otherwise "run_fuzzer" errors out.
|
| 385 |
+
if [ -z "$FUZZER_ARGS" ]; then
|
| 386 |
+
export FUZZER_ARGS="-rss_limit_mb=2560 -timeout=25"
|
| 387 |
+
fi
|
| 388 |
+
|
| 389 |
+
bash -c "run_fuzzer $FUZZER_NAME -runs=0" &> $FUZZER_OUTPUT
|
| 390 |
+
|
| 391 |
+
# Don't output anything if fuzz target hasn't crashed.
|
| 392 |
+
if [ $? -ne 0 ]; then
|
| 393 |
+
echo "BAD BUILD: $FUZZER has a crashing input in its seed corpus:"
|
| 394 |
+
cat $FUZZER_OUTPUT
|
| 395 |
+
return 1
|
| 396 |
+
fi
|
| 397 |
+
|
| 398 |
+
return 0
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
function check_architecture {
|
| 402 |
+
local FUZZER=$1
|
| 403 |
+
local FUZZER_NAME=$(basename $FUZZER)
|
| 404 |
+
|
| 405 |
+
if [ "${FUZZING_LANGUAGE:-}" = "jvm" ]; then
|
| 406 |
+
# The native dependencies of a JVM project are not packaged, but loaded
|
| 407 |
+
# dynamically at runtime and thus cannot be checked here.
|
| 408 |
+
return 0;
|
| 409 |
+
fi
|
| 410 |
+
|
| 411 |
+
if [ "${FUZZING_LANGUAGE:-}" = "javascript" ]; then
|
| 412 |
+
# Jazzer.js fuzzers are wrapper scripts that start the fuzz target with
|
| 413 |
+
# the Jazzer.js CLI.
|
| 414 |
+
return 0;
|
| 415 |
+
fi
|
| 416 |
+
|
| 417 |
+
if [ "${FUZZING_LANGUAGE:-}" = "python" ]; then
|
| 418 |
+
FUZZER=${FUZZER}.pkg
|
| 419 |
+
fi
|
| 420 |
+
|
| 421 |
+
# For fuzztest fuzzers point to the binary instead of launcher script.
|
| 422 |
+
if [[ $FUZZER == *"@"* ]]; then
|
| 423 |
+
FUZZER=(${FUZZER//@/ }[0])
|
| 424 |
+
fi
|
| 425 |
+
|
| 426 |
+
FILE_OUTPUT=$(file $FUZZER)
|
| 427 |
+
if [[ $ARCHITECTURE == "x86_64" ]]
|
| 428 |
+
then
|
| 429 |
+
echo $FILE_OUTPUT | grep "x86-64" > /dev/null
|
| 430 |
+
elif [[ $ARCHITECTURE == "i386" ]]
|
| 431 |
+
then
|
| 432 |
+
echo $FILE_OUTPUT | grep "80386" > /dev/null
|
| 433 |
+
elif [[ $ARCHITECTURE == "aarch64" ]]
|
| 434 |
+
then
|
| 435 |
+
echo $FILE_OUTPUT | grep "aarch64" > /dev/null
|
| 436 |
+
else
|
| 437 |
+
echo "UNSUPPORTED ARCHITECTURE"
|
| 438 |
+
return 1
|
| 439 |
+
fi
|
| 440 |
+
result=$?
|
| 441 |
+
if [[ $result != 0 ]]
|
| 442 |
+
then
|
| 443 |
+
echo "BAD BUILD $FUZZER is not built for architecture: $ARCHITECTURE"
|
| 444 |
+
echo "file command output: $FILE_OUTPUT"
|
| 445 |
+
echo "check_mixed_sanitizers test will fail."
|
| 446 |
+
fi
|
| 447 |
+
return $result
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
function main {
|
| 451 |
+
local FUZZER=$1
|
| 452 |
+
local AUXILIARY_FUZZER=${2:-}
|
| 453 |
+
local checks_failed=0
|
| 454 |
+
local result=0
|
| 455 |
+
|
| 456 |
+
export RUN_FUZZER_MODE="batch"
|
| 457 |
+
check_engine $FUZZER
|
| 458 |
+
result=$?
|
| 459 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 460 |
+
|
| 461 |
+
check_architecture $FUZZER
|
| 462 |
+
result=$?
|
| 463 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 464 |
+
|
| 465 |
+
if [[ "$FUZZING_ENGINE" == centipede \
|
| 466 |
+
&& "$SANITIZER" != none && "${HELPER:-}" == True ]]; then
|
| 467 |
+
check_mixed_sanitizers $AUXILIARY_FUZZER
|
| 468 |
+
else
|
| 469 |
+
check_mixed_sanitizers $FUZZER
|
| 470 |
+
fi
|
| 471 |
+
result=$?
|
| 472 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 473 |
+
|
| 474 |
+
check_startup_crash $FUZZER
|
| 475 |
+
result=$?
|
| 476 |
+
checks_failed=$(( $checks_failed + $result ))
|
| 477 |
+
|
| 478 |
+
# TODO: re-enable after introducing bug auto-filing for bad builds.
|
| 479 |
+
# check_seed_corpus $FUZZER
|
| 480 |
+
return $checks_failed
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
if [ $# -ne 1 -a $# -ne 2 ]; then
|
| 485 |
+
echo "Usage: $0 <fuzz_target_binary> [<auxiliary_binary>]"
|
| 486 |
+
exit 1
|
| 487 |
+
fi
|
| 488 |
+
|
| 489 |
+
# Fuzz target path.
|
| 490 |
+
FUZZER=$1
|
| 491 |
+
AUXILIARY_FUZZER=${2:-}
|
| 492 |
+
|
| 493 |
+
main $FUZZER $AUXILIARY_FUZZER
|
| 494 |
+
exit $?
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/convertcorpus/go.mod
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module oss-fuzz.com/gocoverage/convertcorpus
|
| 2 |
+
|
| 3 |
+
go 1.19
|
| 4 |
+
|
| 5 |
+
require github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20221110144148-3ffc89b74f84
|
| 6 |
+
|
| 7 |
+
require (
|
| 8 |
+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20220824214621-3c06a36a6952 // indirect
|
| 9 |
+
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
|
| 10 |
+
)
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/gocovmerge/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2015, Wade Simmons
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright notice, this
|
| 8 |
+
list of conditions and the following disclaimer.
|
| 9 |
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
| 10 |
+
this list of conditions and the following disclaimer in the documentation
|
| 11 |
+
and/or other materials provided with the distribution.
|
| 12 |
+
|
| 13 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 14 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 15 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 16 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
| 17 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 18 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 19 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 20 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 21 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 22 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/gocovsum/gocovsum.go
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"encoding/json"
|
| 19 |
+
"flag"
|
| 20 |
+
"fmt"
|
| 21 |
+
"log"
|
| 22 |
+
|
| 23 |
+
"go/ast"
|
| 24 |
+
"go/parser"
|
| 25 |
+
"go/token"
|
| 26 |
+
|
| 27 |
+
"golang.org/x/tools/cover"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
type CoverageTotal struct {
|
| 31 |
+
Count int `json:"count"`
|
| 32 |
+
Covered int `json:"covered"`
|
| 33 |
+
Uncovered int `json:"notcovered"`
|
| 34 |
+
Percent float64 `json:"percent"`
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
type CoverageTotals struct {
|
| 38 |
+
Functions CoverageTotal `json:"functions,omitempty"`
|
| 39 |
+
Lines CoverageTotal `json:"lines,omitempty"`
|
| 40 |
+
Regions CoverageTotal `json:"regions,omitempty"`
|
| 41 |
+
Instantiations CoverageTotal `json:"instantiations,omitempty"`
|
| 42 |
+
Branches CoverageTotal `json:"branches,omitempty"`
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
type CoverageFile struct {
|
| 46 |
+
Summary CoverageTotals `json:"summary,omitempty"`
|
| 47 |
+
Filename string `json:"filename,omitempty"`
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
type CoverageData struct {
|
| 51 |
+
Totals CoverageTotals `json:"totals,omitempty"`
|
| 52 |
+
Files []CoverageFile `json:"files,omitempty"`
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
type PositionInterval struct {
|
| 56 |
+
start token.Position
|
| 57 |
+
end token.Position
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
type CoverageSummary struct {
|
| 61 |
+
Data []CoverageData `json:"data,omitempty"`
|
| 62 |
+
Type string `json:"type,omitempty"`
|
| 63 |
+
Version string `json:"version,omitempty"`
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
func isFunctionCovered(s token.Position, e token.Position, blocks []cover.ProfileBlock) bool {
|
| 67 |
+
for _, b := range blocks {
|
| 68 |
+
if b.StartLine >= s.Line && b.StartLine <= e.Line && b.EndLine >= s.Line && b.EndLine <= e.Line {
|
| 69 |
+
if b.Count > 0 {
|
| 70 |
+
return true
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
return false
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
func computePercent(s *CoverageTotals) {
|
| 78 |
+
if s.Regions.Count > 0 {
|
| 79 |
+
s.Regions.Percent = float64(100*s.Regions.Covered) / float64(s.Regions.Count)
|
| 80 |
+
}
|
| 81 |
+
if s.Lines.Count > 0 {
|
| 82 |
+
s.Lines.Percent = float64(100*s.Lines.Covered) / float64(s.Lines.Count)
|
| 83 |
+
}
|
| 84 |
+
if s.Functions.Count > 0 {
|
| 85 |
+
s.Functions.Percent = float64(100*s.Functions.Covered) / float64(s.Functions.Count)
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
func main() {
|
| 90 |
+
flag.Parse()
|
| 91 |
+
|
| 92 |
+
if len(flag.Args()) != 1 {
|
| 93 |
+
log.Fatalf("needs exactly one argument")
|
| 94 |
+
}
|
| 95 |
+
profiles, err := cover.ParseProfiles(flag.Args()[0])
|
| 96 |
+
if err != nil {
|
| 97 |
+
log.Fatalf("failed to parse profiles: %v", err)
|
| 98 |
+
}
|
| 99 |
+
r := CoverageSummary{}
|
| 100 |
+
r.Type = "oss-fuzz.go.coverage.json.export"
|
| 101 |
+
r.Version = "2.0.1"
|
| 102 |
+
r.Data = make([]CoverageData, 1)
|
| 103 |
+
for _, p := range profiles {
|
| 104 |
+
fset := token.NewFileSet() // positions are relative to fset
|
| 105 |
+
f, err := parser.ParseFile(fset, p.FileName, nil, 0)
|
| 106 |
+
if err != nil {
|
| 107 |
+
log.Printf("failed to parse go file: %v", err)
|
| 108 |
+
continue
|
| 109 |
+
}
|
| 110 |
+
fileCov := CoverageFile{}
|
| 111 |
+
fileCov.Filename = p.FileName
|
| 112 |
+
ast.Inspect(f, func(n ast.Node) bool {
|
| 113 |
+
switch x := n.(type) {
|
| 114 |
+
case *ast.FuncLit:
|
| 115 |
+
startf := fset.Position(x.Pos())
|
| 116 |
+
endf := fset.Position(x.End())
|
| 117 |
+
fileCov.Summary.Functions.Count++
|
| 118 |
+
if isFunctionCovered(startf, endf, p.Blocks) {
|
| 119 |
+
fileCov.Summary.Functions.Covered++
|
| 120 |
+
} else {
|
| 121 |
+
fileCov.Summary.Functions.Uncovered++
|
| 122 |
+
}
|
| 123 |
+
case *ast.FuncDecl:
|
| 124 |
+
startf := fset.Position(x.Pos())
|
| 125 |
+
endf := fset.Position(x.End())
|
| 126 |
+
fileCov.Summary.Functions.Count++
|
| 127 |
+
if isFunctionCovered(startf, endf, p.Blocks) {
|
| 128 |
+
fileCov.Summary.Functions.Covered++
|
| 129 |
+
} else {
|
| 130 |
+
fileCov.Summary.Functions.Uncovered++
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
return true
|
| 134 |
+
})
|
| 135 |
+
|
| 136 |
+
for _, b := range p.Blocks {
|
| 137 |
+
fileCov.Summary.Regions.Count++
|
| 138 |
+
if b.Count > 0 {
|
| 139 |
+
fileCov.Summary.Regions.Covered++
|
| 140 |
+
} else {
|
| 141 |
+
fileCov.Summary.Regions.Uncovered++
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
fileCov.Summary.Lines.Count += b.NumStmt
|
| 145 |
+
if b.Count > 0 {
|
| 146 |
+
fileCov.Summary.Lines.Covered += b.NumStmt
|
| 147 |
+
} else {
|
| 148 |
+
fileCov.Summary.Lines.Uncovered += b.NumStmt
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
r.Data[0].Totals.Regions.Count += fileCov.Summary.Regions.Count
|
| 152 |
+
r.Data[0].Totals.Regions.Covered += fileCov.Summary.Regions.Covered
|
| 153 |
+
r.Data[0].Totals.Regions.Uncovered += fileCov.Summary.Regions.Uncovered
|
| 154 |
+
r.Data[0].Totals.Lines.Count += fileCov.Summary.Lines.Count
|
| 155 |
+
r.Data[0].Totals.Lines.Covered += fileCov.Summary.Lines.Covered
|
| 156 |
+
r.Data[0].Totals.Lines.Uncovered += fileCov.Summary.Lines.Uncovered
|
| 157 |
+
r.Data[0].Totals.Functions.Count += fileCov.Summary.Functions.Count
|
| 158 |
+
r.Data[0].Totals.Functions.Covered += fileCov.Summary.Functions.Covered
|
| 159 |
+
r.Data[0].Totals.Functions.Uncovered += fileCov.Summary.Functions.Uncovered
|
| 160 |
+
|
| 161 |
+
computePercent(&fileCov.Summary)
|
| 162 |
+
r.Data[0].Files = append(r.Data[0].Files, fileCov)
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
computePercent(&r.Data[0].Totals)
|
| 166 |
+
o, err := json.Marshal(r)
|
| 167 |
+
if err != nil {
|
| 168 |
+
log.Fatalf("failed to generate json: %v", err)
|
| 169 |
+
}
|
| 170 |
+
fmt.Printf(string(o))
|
| 171 |
+
}
|
local-test-commons-compress-full-01-vuln_2/fuzz-tooling/infra/base-images/base-runner/gocoverage/pprof-merge/main.go
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2019 Google Inc. All Rights Reserved.
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"flag"
|
| 19 |
+
"log"
|
| 20 |
+
"os"
|
| 21 |
+
|
| 22 |
+
"github.com/google/pprof/profile"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
var (
|
| 26 |
+
output string
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
func main() {
|
| 30 |
+
flag.StringVar(&output, "o", "merged.data", "")
|
| 31 |
+
flag.Parse()
|
| 32 |
+
|
| 33 |
+
files := os.Args[1:]
|
| 34 |
+
if len(files) == 0 {
|
| 35 |
+
log.Fatal("Give profiles files as arguments")
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
var profiles []*profile.Profile
|
| 39 |
+
for _, fname := range files {
|
| 40 |
+
f, err := os.Open(fname)
|
| 41 |
+
if err != nil {
|
| 42 |
+
log.Fatalf("Cannot open profile file at %q: %v", fname, err)
|
| 43 |
+
}
|
| 44 |
+
p, err := profile.Parse(f)
|
| 45 |
+
if err != nil {
|
| 46 |
+
log.Fatalf("Cannot parse profile at %q: %v", fname, err)
|
| 47 |
+
}
|
| 48 |
+
profiles = append(profiles, p)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
merged, err := profile.Merge(profiles)
|
| 52 |
+
if err != nil {
|
| 53 |
+
log.Fatalf("Cannot merge profiles: %v", err)
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
out, err := os.OpenFile(output, os.O_RDWR|os.O_CREATE, 0755)
|
| 57 |
+
if err != nil {
|
| 58 |
+
log.Fatalf("Cannot open output to write: %v", err)
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if err := merged.Write(out); err != nil {
|
| 62 |
+
log.Fatalf("Cannot write merged profile to file: %v", err)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if err := out.Close(); err != nil {
|
| 66 |
+
log.Printf("Error when closing the output file: %v", err)
|
| 67 |
+
}
|
| 68 |
+
}
|