Add files using upload-large-folder tool
Browse files- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder-jvm/Dockerfile +68 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder-ruby/Dockerfile +56 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder-ruby/ruzzy-build +28 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/build_jcc.bash +25 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/go.mod +3 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/jcc.go +88 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/jcc2.go +401 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/jcc_test.go +186 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/.gitignore +2 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/cfile.c +18 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/cpp.cc +18 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/README.md +3 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pyproject.toml +22 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/yaml_deserialization.py +42 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/setup.py +21 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/eval_command_injection.py +52 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/subprocess_popen_injection.py +51 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/test_data/culprit-commit.txt +30 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-clang/Dockerfile +79 -0
- local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-clang/checkout_build_install_llvm.sh +246 -0
local-test-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder-ruby/Dockerfile
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
#
|
| 15 |
+
################################################################################
|
| 16 |
+
|
| 17 |
+
ARG IMG_TAG=latest
|
| 18 |
+
FROM ghcr.io/aixcc-finals/base-builder:${IMG_TAG}
|
| 19 |
+
|
| 20 |
+
RUN git clone https://github.com/trailofbits/ruzzy.git $SRC/ruzzy
|
| 21 |
+
|
| 22 |
+
RUN install_ruby.sh
|
| 23 |
+
ENV PATH="$PATH:/usr/local/rvm/rubies/ruby-3.3.1/bin"
|
| 24 |
+
|
| 25 |
+
RUN gem update --system 3.5.11
|
| 26 |
+
|
| 27 |
+
# Install ruzzy
|
| 28 |
+
WORKDIR $SRC/ruzzy
|
| 29 |
+
|
| 30 |
+
# The MAKE variable allows overwriting the make command at runtime. This forces the
|
| 31 |
+
# Ruby C extension to respect ENV variables when compiling, like CC, CFLAGS, etc.
|
| 32 |
+
ENV MAKE="make --environment-overrides V=1"
|
| 33 |
+
|
| 34 |
+
RUN CC="clang" \
|
| 35 |
+
CXX="clang++" \
|
| 36 |
+
LDSHARED="clang -shared" \
|
| 37 |
+
LDSHAREDXX="clang++ -shared" \
|
| 38 |
+
gem build
|
| 39 |
+
|
| 40 |
+
RUN MAKE="make --environment-overrides V=1" \
|
| 41 |
+
CC="clang" \
|
| 42 |
+
CXX="clang++" \
|
| 43 |
+
LDSHARED="clang -shared" \
|
| 44 |
+
LDSHAREDXX="clang++ -shared" \
|
| 45 |
+
CXXFLAGS="-fPIC" \
|
| 46 |
+
CFLAGS="-fPIC" \
|
| 47 |
+
RUZZY_DEBUG=1 gem install --install-dir /install/ruzzy --development --verbose ruzzy-*.gem
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
ENV LDSHARED="$CC -shared"
|
| 51 |
+
ENV LDSHAREDXX="$CXX -shared"
|
| 52 |
+
|
| 53 |
+
ENV GEM_HOME="$OUT/fuzz-gem"
|
| 54 |
+
ENV GEM_PATH="/install/ruzzy"
|
| 55 |
+
|
| 56 |
+
COPY ruzzy-build /usr/bin/ruzzy-build
|
local-test-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/build_jcc.bash
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash -eu
|
| 2 |
+
#
|
| 3 |
+
# Copyright 2023 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 |
+
go build jcc.go
|
| 20 |
+
go build jcc2.go
|
| 21 |
+
gsutil cp jcc gs://clusterfuzz-builds/jcc/clang++-jcc
|
| 22 |
+
gsutil cp jcc gs://clusterfuzz-builds/jcc/clang-jcc
|
| 23 |
+
|
| 24 |
+
gsutil cp jcc2 gs://clusterfuzz-builds/jcc/clang++-jcc2
|
| 25 |
+
gsutil cp jcc2 gs://clusterfuzz-builds/jcc/clang-jcc2
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/go.mod
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module github.com/google/jcc
|
| 2 |
+
|
| 3 |
+
go 1.21
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/jcc.go
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"bytes"
|
| 19 |
+
"fmt"
|
| 20 |
+
"log"
|
| 21 |
+
"os"
|
| 22 |
+
"os/exec"
|
| 23 |
+
"path/filepath"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
func ExecBuildCommand(bin string, args []string) (int, string, string) {
|
| 27 |
+
// Executes the original command.
|
| 28 |
+
cmd := exec.Command(bin, args...)
|
| 29 |
+
var outb, errb bytes.Buffer
|
| 30 |
+
cmd.Stdout = &outb
|
| 31 |
+
cmd.Stderr = &errb
|
| 32 |
+
cmd.Stdin = os.Stdin
|
| 33 |
+
cmd.Run()
|
| 34 |
+
return cmd.ProcessState.ExitCode(), outb.String(), errb.String()
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
func Compile(bin string, args []string) (int, string, string) {
|
| 38 |
+
// Run the actual command.
|
| 39 |
+
return ExecBuildCommand(bin, args)
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
func AppendStringToFile(filepath, new_content string) error {
|
| 43 |
+
// Appends |new_content| to the content of |filepath|.
|
| 44 |
+
file, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
| 45 |
+
if err != nil {
|
| 46 |
+
return err
|
| 47 |
+
}
|
| 48 |
+
defer file.Close()
|
| 49 |
+
|
| 50 |
+
_, err = file.WriteString(new_content)
|
| 51 |
+
return err
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
func WriteStdErrOut(args []string, outstr string, errstr string) {
|
| 55 |
+
// Prints |outstr| to stdout, prints |errstr| to stderr, and saves |errstr| to err.log.
|
| 56 |
+
fmt.Print(outstr)
|
| 57 |
+
fmt.Fprint(os.Stderr, errstr)
|
| 58 |
+
// Record what compile args produced the error and the error itself in log file.
|
| 59 |
+
AppendStringToFile("/tmp/err.log", fmt.Sprintf("%s\n", args)+errstr)
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
func main() {
|
| 63 |
+
f, err := os.OpenFile("/tmp/jcc.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
| 64 |
+
|
| 65 |
+
if err != nil {
|
| 66 |
+
log.Println(err)
|
| 67 |
+
}
|
| 68 |
+
defer f.Close()
|
| 69 |
+
if _, err := f.WriteString(fmt.Sprintf("%s\n", os.Args)); err != nil {
|
| 70 |
+
log.Println(err)
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
args := os.Args[1:]
|
| 74 |
+
basename := filepath.Base(os.Args[0])
|
| 75 |
+
isCPP := basename == "clang++-jcc"
|
| 76 |
+
newArgs := args
|
| 77 |
+
|
| 78 |
+
var bin string
|
| 79 |
+
if isCPP {
|
| 80 |
+
bin = "clang++"
|
| 81 |
+
} else {
|
| 82 |
+
bin = "clang"
|
| 83 |
+
}
|
| 84 |
+
fullCmdArgs := append([]string{bin}, newArgs...)
|
| 85 |
+
retcode, out, errstr := Compile(bin, newArgs)
|
| 86 |
+
WriteStdErrOut(fullCmdArgs, out, errstr)
|
| 87 |
+
os.Exit(retcode)
|
| 88 |
+
}
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/jcc2.go
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2024 Google LLC
|
| 2 |
+
//
|
| 3 |
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
// you may not use this file except in compliance with the License.
|
| 5 |
+
// You may obtain a copy of the License at
|
| 6 |
+
//
|
| 7 |
+
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
//
|
| 9 |
+
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
// See the License for the specific language governing permissions and
|
| 13 |
+
// limitations under the License.
|
| 14 |
+
|
| 15 |
+
package main
|
| 16 |
+
|
| 17 |
+
import (
|
| 18 |
+
"bytes"
|
| 19 |
+
"encoding/json"
|
| 20 |
+
"errors"
|
| 21 |
+
"fmt"
|
| 22 |
+
"io/fs"
|
| 23 |
+
"io/ioutil"
|
| 24 |
+
"log"
|
| 25 |
+
"os"
|
| 26 |
+
"os/exec"
|
| 27 |
+
"path/filepath"
|
| 28 |
+
"regexp"
|
| 29 |
+
"strings"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
var MaxMissingHeaderFiles = 10
|
| 33 |
+
var CppifyHeadersMagicString = "\n/* JCCCppifyHeadersMagicString */\n"
|
| 34 |
+
|
| 35 |
+
func CopyFile(src string, dst string) {
|
| 36 |
+
contents, err := ioutil.ReadFile(src)
|
| 37 |
+
if err != nil {
|
| 38 |
+
panic(err)
|
| 39 |
+
}
|
| 40 |
+
err = ioutil.WriteFile(dst, contents, 0644)
|
| 41 |
+
if err != nil {
|
| 42 |
+
panic(err)
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func TryFixCCompilation(cmdline []string) ([]string, int, string, string) {
|
| 47 |
+
var newFile string = ""
|
| 48 |
+
for i, arg := range cmdline {
|
| 49 |
+
if !strings.HasSuffix(arg, ".c") {
|
| 50 |
+
continue
|
| 51 |
+
}
|
| 52 |
+
if _, err := os.Stat(arg); errors.Is(err, os.ErrNotExist) {
|
| 53 |
+
continue
|
| 54 |
+
}
|
| 55 |
+
newFile = strings.TrimSuffix(arg, ".c")
|
| 56 |
+
newFile += ".cpp"
|
| 57 |
+
CopyFile(arg, newFile)
|
| 58 |
+
CppifyHeaderIncludesFromFile(newFile)
|
| 59 |
+
cmdline[i] = newFile
|
| 60 |
+
break
|
| 61 |
+
}
|
| 62 |
+
if newFile == "" {
|
| 63 |
+
return []string{}, 1, "", ""
|
| 64 |
+
}
|
| 65 |
+
cppBin := "clang++"
|
| 66 |
+
newCmdline := []string{"-stdlib=libc++"}
|
| 67 |
+
newCmdline = append(cmdline, newCmdline...)
|
| 68 |
+
newFullArgs := append([]string{cppBin}, newCmdline...)
|
| 69 |
+
|
| 70 |
+
retcode, out, err := Compile(cppBin, newCmdline)
|
| 71 |
+
if retcode == 0 {
|
| 72 |
+
return newFullArgs, retcode, out, err
|
| 73 |
+
}
|
| 74 |
+
correctedCmdline, corrected, _ := CorrectMissingHeaders(cppBin, newCmdline)
|
| 75 |
+
if corrected {
|
| 76 |
+
return append([]string{cppBin}, correctedCmdline...), 0, "", ""
|
| 77 |
+
}
|
| 78 |
+
return newFullArgs, retcode, out, err
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
func ExtractMissingHeader(compilerOutput string) (string, bool) {
|
| 82 |
+
r := regexp.MustCompile(`fatal error: ['|<](?P<header>[a-zA-z0-9\/\.]+)['|>] file not found`)
|
| 83 |
+
matches := r.FindStringSubmatch(compilerOutput)
|
| 84 |
+
if len(matches) == 0 {
|
| 85 |
+
return "", false
|
| 86 |
+
}
|
| 87 |
+
return matches[1], true
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
func ReplaceMissingHeaderInFile(srcFilename, curHeader, replacementHeader string) error {
|
| 91 |
+
srcFile, err := os.Open(srcFilename)
|
| 92 |
+
if err != nil {
|
| 93 |
+
return err
|
| 94 |
+
}
|
| 95 |
+
srcBytes, err := ioutil.ReadAll(srcFile)
|
| 96 |
+
if err != nil {
|
| 97 |
+
return err
|
| 98 |
+
}
|
| 99 |
+
src := string(srcBytes)
|
| 100 |
+
newSrc := ReplaceMissingHeader(src, curHeader, replacementHeader)
|
| 101 |
+
b := []byte(newSrc)
|
| 102 |
+
err = ioutil.WriteFile(srcFilename, b, 0644)
|
| 103 |
+
if err != nil {
|
| 104 |
+
return err
|
| 105 |
+
}
|
| 106 |
+
return nil
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
func ReplaceMissingHeader(src, curHeader, replacementHeader string) string {
|
| 110 |
+
re := regexp.MustCompile(`#include ["|<]` + curHeader + `["|>]\n`)
|
| 111 |
+
replacement := "#include \"" + replacementHeader + "\"\n"
|
| 112 |
+
return re.ReplaceAllString(src, replacement)
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
func GetHeaderCorrectedFilename(compilerErr string) (string, string, bool) {
|
| 116 |
+
re := regexp.MustCompile(`(?P<buggy>[a-z\/\-\_0-9A-z\.]+):.* fatal error: .* file not found`)
|
| 117 |
+
matches := re.FindStringSubmatch(compilerErr)
|
| 118 |
+
if len(matches) < 2 {
|
| 119 |
+
return "", "", false
|
| 120 |
+
}
|
| 121 |
+
oldFilename := matches[1]
|
| 122 |
+
base := filepath.Base(oldFilename)
|
| 123 |
+
root := filepath.Dir(oldFilename)
|
| 124 |
+
newFilename := root + "/jcc-corrected-" + base
|
| 125 |
+
return oldFilename, newFilename, true
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
func GetHeaderCorrectedCmd(cmd []string, compilerErr string) ([]string, string, error) {
|
| 129 |
+
oldFilename, newFilename, success := GetHeaderCorrectedFilename(compilerErr)
|
| 130 |
+
if !success {
|
| 131 |
+
return cmd, "", errors.New("Couldn't find buggy file")
|
| 132 |
+
}
|
| 133 |
+
// Make new cmd.
|
| 134 |
+
newCmd := make([]string, len(cmd))
|
| 135 |
+
for i, part := range cmd {
|
| 136 |
+
newCmd[i] = part
|
| 137 |
+
}
|
| 138 |
+
found := false
|
| 139 |
+
for i, filename := range newCmd {
|
| 140 |
+
if filename == oldFilename {
|
| 141 |
+
newCmd[i] = newFilename
|
| 142 |
+
found = true
|
| 143 |
+
break
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
CopyFile(oldFilename, newFilename)
|
| 147 |
+
if found {
|
| 148 |
+
return newCmd, newFilename, nil
|
| 149 |
+
}
|
| 150 |
+
return cmd, "", errors.New("Couldn't find file")
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
func CorrectMissingHeaders(bin string, cmd []string) ([]string, bool, error) {
|
| 154 |
+
|
| 155 |
+
_, _, stderr := Compile(bin, cmd)
|
| 156 |
+
cmd, correctedFilename, err := GetHeaderCorrectedCmd(cmd, stderr)
|
| 157 |
+
if err != nil {
|
| 158 |
+
return cmd, false, err
|
| 159 |
+
}
|
| 160 |
+
for i := 0; i < MaxMissingHeaderFiles; i++ {
|
| 161 |
+
fixed, hasBrokenHeaders := TryCompileAndFixHeadersOnce(bin, cmd, correctedFilename)
|
| 162 |
+
if fixed {
|
| 163 |
+
return cmd, true, nil
|
| 164 |
+
}
|
| 165 |
+
if !hasBrokenHeaders {
|
| 166 |
+
return cmd, false, nil
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
return cmd, false, nil
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
func ExecBuildCommand(bin string, args []string) (int, string, string) {
|
| 173 |
+
// Executes the original command.
|
| 174 |
+
cmd := exec.Command(bin, args...)
|
| 175 |
+
var outb, errb bytes.Buffer
|
| 176 |
+
cmd.Stdout = &outb
|
| 177 |
+
cmd.Stderr = &errb
|
| 178 |
+
cmd.Stdin = os.Stdin
|
| 179 |
+
cmd.Run()
|
| 180 |
+
return cmd.ProcessState.ExitCode(), outb.String(), errb.String()
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
func Compile(bin string, args []string) (int, string, string) {
|
| 184 |
+
// Run the actual command.
|
| 185 |
+
return ExecBuildCommand(bin, args)
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
func TryCompileAndFixHeadersOnce(bin string, cmd []string, filename string) (fixed, hasBrokenHeaders bool) {
|
| 189 |
+
retcode, _, err := Compile(bin, cmd)
|
| 190 |
+
if retcode == 0 {
|
| 191 |
+
fixed = true
|
| 192 |
+
hasBrokenHeaders = false
|
| 193 |
+
return
|
| 194 |
+
}
|
| 195 |
+
missingHeader, isMissing := ExtractMissingHeader(err)
|
| 196 |
+
if !isMissing {
|
| 197 |
+
fixed = false
|
| 198 |
+
hasBrokenHeaders = false
|
| 199 |
+
return
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
newHeaderPath, found := FindMissingHeader(missingHeader)
|
| 203 |
+
if !found {
|
| 204 |
+
fixed = false
|
| 205 |
+
hasBrokenHeaders = true
|
| 206 |
+
return false, true
|
| 207 |
+
}
|
| 208 |
+
ReplaceMissingHeaderInFile(filename, missingHeader, newHeaderPath)
|
| 209 |
+
return false, true
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
func FindMissingHeader(missingHeader string) (string, bool) {
|
| 213 |
+
envVar := "JCC_MISSING_HEADER_SEARCH_PATH"
|
| 214 |
+
var searchPath string
|
| 215 |
+
searchPath, exists := os.LookupEnv(envVar)
|
| 216 |
+
if !exists {
|
| 217 |
+
searchPath = "/src"
|
| 218 |
+
}
|
| 219 |
+
searchPath, _ = filepath.Abs(searchPath)
|
| 220 |
+
var headerLocation string
|
| 221 |
+
missingHeader = "/" + missingHeader
|
| 222 |
+
find := func(path string, d fs.DirEntry, err error) error {
|
| 223 |
+
if err != nil {
|
| 224 |
+
return err
|
| 225 |
+
}
|
| 226 |
+
if d.IsDir() {
|
| 227 |
+
return nil
|
| 228 |
+
}
|
| 229 |
+
if strings.HasSuffix(path, missingHeader) {
|
| 230 |
+
headerLocation = path
|
| 231 |
+
return nil
|
| 232 |
+
}
|
| 233 |
+
return nil
|
| 234 |
+
}
|
| 235 |
+
filepath.WalkDir(searchPath, find)
|
| 236 |
+
if headerLocation == "" {
|
| 237 |
+
return "", false
|
| 238 |
+
}
|
| 239 |
+
return headerLocation, true
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
func CppifyHeaderIncludesFromFile(srcFile string) error {
|
| 243 |
+
contentsBytes, err := ioutil.ReadFile(srcFile)
|
| 244 |
+
if err != nil {
|
| 245 |
+
return err
|
| 246 |
+
}
|
| 247 |
+
contents := string(contentsBytes[:])
|
| 248 |
+
contents, err = CppifyHeaderIncludes(contents)
|
| 249 |
+
if err != nil {
|
| 250 |
+
return err
|
| 251 |
+
}
|
| 252 |
+
b := []byte(contents)
|
| 253 |
+
err = ioutil.WriteFile(srcFile, b, 0644)
|
| 254 |
+
return err
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
func CppifyHeaderIncludes(contents string) (string, error) {
|
| 258 |
+
shouldCppify, exists := os.LookupEnv("JCC_CPPIFY_PROJECT_HEADERS")
|
| 259 |
+
if !exists || strings.Compare(shouldCppify, "0") == 0 {
|
| 260 |
+
return contents, nil
|
| 261 |
+
}
|
| 262 |
+
if strings.Contains(contents, CppifyHeadersMagicString) {
|
| 263 |
+
return contents, nil
|
| 264 |
+
}
|
| 265 |
+
re := regexp.MustCompile(`\#include \"(?P<header>.+)\"\n`)
|
| 266 |
+
matches := re.FindAllStringSubmatch(contents, -1)
|
| 267 |
+
if len(matches) == 0 {
|
| 268 |
+
return "", nil // !!!
|
| 269 |
+
}
|
| 270 |
+
for i, match := range matches {
|
| 271 |
+
if i == 0 {
|
| 272 |
+
// So we don't cppify twice.
|
| 273 |
+
contents += CppifyHeadersMagicString
|
| 274 |
+
}
|
| 275 |
+
oldStr := match[0]
|
| 276 |
+
replacement := "extern \"C\" {\n#include \"" + match[1] + "\"\n}\n"
|
| 277 |
+
contents = strings.Replace(contents, oldStr, replacement, 1)
|
| 278 |
+
if strings.Compare(contents, "") == 0 {
|
| 279 |
+
panic("Failed to replace")
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
return contents, nil
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
func AppendStringToFile(filepath, new_content string) error {
|
| 286 |
+
// Appends |new_content| to the content of |filepath|.
|
| 287 |
+
file, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
| 288 |
+
if err != nil {
|
| 289 |
+
return err
|
| 290 |
+
}
|
| 291 |
+
defer file.Close()
|
| 292 |
+
|
| 293 |
+
_, err = file.WriteString(new_content)
|
| 294 |
+
return err
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
func WriteStdErrOut(args []string, outstr string, errstr string) {
|
| 298 |
+
// Prints |outstr| to stdout, prints |errstr| to stderr, and saves |errstr| to err.log.
|
| 299 |
+
fmt.Print(outstr)
|
| 300 |
+
fmt.Fprint(os.Stderr, errstr)
|
| 301 |
+
// Record what compile args produced the error and the error itself in log file.
|
| 302 |
+
AppendStringToFile("/workspace/err.log", fmt.Sprintf("%s\n", args)+errstr)
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
func main() {
|
| 306 |
+
f, err := os.OpenFile("/tmp/jcc.log", os.O_CREATE|os.O_WRONLY, 0644)
|
| 307 |
+
if err != nil {
|
| 308 |
+
log.Println(err)
|
| 309 |
+
}
|
| 310 |
+
defer f.Close()
|
| 311 |
+
if _, err := f.WriteString(fmt.Sprintf("%s\n", os.Args)); err != nil {
|
| 312 |
+
log.Println(err)
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
args := os.Args[1:]
|
| 316 |
+
if args[0] == "unfreeze" {
|
| 317 |
+
fmt.Println("unfreeze")
|
| 318 |
+
unfreeze()
|
| 319 |
+
}
|
| 320 |
+
basename := filepath.Base(os.Args[0])
|
| 321 |
+
isCPP := basename == "clang++-jcc"
|
| 322 |
+
newArgs := append(args, "-w")
|
| 323 |
+
|
| 324 |
+
var bin string
|
| 325 |
+
if isCPP {
|
| 326 |
+
bin = "clang++"
|
| 327 |
+
newArgs = append(args, "-stdlib=libc++")
|
| 328 |
+
} else {
|
| 329 |
+
bin = "clang"
|
| 330 |
+
}
|
| 331 |
+
fullCmdArgs := append([]string{bin}, newArgs...)
|
| 332 |
+
if IsCompilingTarget(fullCmdArgs) {
|
| 333 |
+
WriteTargetArgsAndCommitImage(fullCmdArgs)
|
| 334 |
+
os.Exit(0)
|
| 335 |
+
}
|
| 336 |
+
retcode, out, errstr := Compile(bin, newArgs)
|
| 337 |
+
WriteStdErrOut(fullCmdArgs, out, errstr)
|
| 338 |
+
os.Exit(retcode)
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
type BuildCommand struct {
|
| 342 |
+
CWD string `json:"CWD"`
|
| 343 |
+
CMD []string `json:"CMD"`
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
func WriteTargetArgsAndCommitImage(cmdline []string) {
|
| 347 |
+
log.Println("WRITE COMMAND")
|
| 348 |
+
f, _ := os.OpenFile("/out/statefile.json", os.O_CREATE|os.O_WRONLY, 0644)
|
| 349 |
+
wd, _ := os.Getwd()
|
| 350 |
+
buildcmd := BuildCommand{
|
| 351 |
+
CWD: wd,
|
| 352 |
+
CMD: cmdline,
|
| 353 |
+
}
|
| 354 |
+
jsonData, _ := json.Marshal(buildcmd)
|
| 355 |
+
f.Write(jsonData)
|
| 356 |
+
f.Close()
|
| 357 |
+
hostname, _ := os.Hostname()
|
| 358 |
+
dockerArgs := []string{"commit", hostname, "frozen"}
|
| 359 |
+
cmd := exec.Command("docker", dockerArgs...)
|
| 360 |
+
var outb, errb bytes.Buffer
|
| 361 |
+
cmd.Stdout = &outb
|
| 362 |
+
cmd.Stderr = &errb
|
| 363 |
+
cmd.Stdin = os.Stdin
|
| 364 |
+
cmd.Run()
|
| 365 |
+
fmt.Println(outb.String(), errb.String())
|
| 366 |
+
fmt.Println("COMMIT IMAGE")
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
func IsCompilingTarget(cmdline []string) bool {
|
| 370 |
+
for _, arg := range cmdline {
|
| 371 |
+
// This can fail if people do crazy things they aren't supposed
|
| 372 |
+
// to such as using some other means to link in libFuzzer.
|
| 373 |
+
if arg == "-fsanitize=fuzzer" {
|
| 374 |
+
return true
|
| 375 |
+
}
|
| 376 |
+
if arg == "-lFuzzingEngine" {
|
| 377 |
+
return true
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
return false
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
func parseCommand(command string) (string, []string) {
|
| 384 |
+
args := strings.Fields(command)
|
| 385 |
+
commandBin := args[0]
|
| 386 |
+
commandArgs := args[1:]
|
| 387 |
+
return commandBin, commandArgs
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
func unfreeze() {
|
| 391 |
+
content, err := ioutil.ReadFile("/out/statefile.json")
|
| 392 |
+
if err != nil {
|
| 393 |
+
log.Fatal(err)
|
| 394 |
+
}
|
| 395 |
+
var command BuildCommand
|
| 396 |
+
json.Unmarshal(content, &command)
|
| 397 |
+
bin, args := parseCommand(strings.Join(command.CMD, " "))
|
| 398 |
+
os.Chdir(command.CWD)
|
| 399 |
+
ExecBuildCommand(bin, args)
|
| 400 |
+
os.Exit(0)
|
| 401 |
+
}
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/jcc_test.go
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"os"
|
| 6 |
+
"strings"
|
| 7 |
+
"testing"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
func TestExtractMissingHeader(t *testing.T) {
|
| 11 |
+
missingHeaderMessage := `path/to/file.cpp:8:10: fatal error: 'missingheader.h' file not found
|
| 12 |
+
|
| 13 |
+
#include "missingheader.h"
|
| 14 |
+
|
| 15 |
+
^~~~~~~~~~~~
|
| 16 |
+
|
| 17 |
+
1 error generated.
|
| 18 |
+
`
|
| 19 |
+
|
| 20 |
+
res, _ := ExtractMissingHeader(missingHeaderMessage)
|
| 21 |
+
expected := "missingheader.h"
|
| 22 |
+
if strings.Compare(res, expected) != 0 {
|
| 23 |
+
t.Errorf("Got: %s. Expected: %s.", res, expected)
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
func TestGetHeaderCorrectedFilename(t *testing.T) {
|
| 28 |
+
missingHeaderMessage := `path/to/file.cpp:8:10: fatal error: 'missingheader.h' file not found
|
| 29 |
+
|
| 30 |
+
#include "missingheader.h"
|
| 31 |
+
|
| 32 |
+
^~~~~~~~~~~~
|
| 33 |
+
|
| 34 |
+
1 error generated.
|
| 35 |
+
`
|
| 36 |
+
_, correctedFilename, _ := GetHeaderCorrectedFilename(missingHeaderMessage)
|
| 37 |
+
expected := "path/to/jcc-corrected-file.cpp"
|
| 38 |
+
if strings.Compare(correctedFilename, expected) != 0 {
|
| 39 |
+
t.Errorf("Got: %s. Expected: %s.", correctedFilename, expected)
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
func TestFindMissingHeader(t *testing.T) {
|
| 44 |
+
pwd, _ := os.Getwd()
|
| 45 |
+
t.Setenv("JCC_MISSING_HEADER_SEARCH_PATH", pwd)
|
| 46 |
+
|
| 47 |
+
location, _ := FindMissingHeader("header.h")
|
| 48 |
+
expected := pwd + "/testdata/path/to/header.h"
|
| 49 |
+
if strings.Compare(location, expected) != 0 {
|
| 50 |
+
t.Errorf("Got: %s. Expected: %s.", location, expected)
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
func TestCorrectMissingHeaders(t *testing.T) {
|
| 55 |
+
pwd, _ := os.Getwd()
|
| 56 |
+
t.Setenv("JCC_MISSING_HEADER_SEARCH_PATH", pwd)
|
| 57 |
+
cfile := pwd + "/testdata/cfile.c"
|
| 58 |
+
cmd := [4]string{"-fsanitize=address", cfile, "-o", "/tmp/blah"}
|
| 59 |
+
res, err := CorrectMissingHeaders("clang", cmd[:])
|
| 60 |
+
if !res {
|
| 61 |
+
fmt.Println(err)
|
| 62 |
+
t.Errorf("Expected successful compilation")
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
func TestGetHeaderCorrectedCmd(t *testing.T) {
|
| 67 |
+
compilerErr := `testdata/cpp.cc:8:10: fatal error: 'missingheader.h' file not found
|
| 68 |
+
|
| 69 |
+
#include "missingheader.h"
|
| 70 |
+
|
| 71 |
+
^~~~~~~~~~~~
|
| 72 |
+
|
| 73 |
+
1 error generated.
|
| 74 |
+
`
|
| 75 |
+
|
| 76 |
+
cmd := [3]string{"-fsanitize=address", "file.cpp", "path/to/cpp.cc"}
|
| 77 |
+
expectedFixedCmd := [3]string{"-fanitize=address", "file.cpp", "path/to/jcc-corrected-cpp.cc"}
|
| 78 |
+
fixedCmd, _, _ := GetHeaderCorrectedCmd(cmd[:], compilerErr)
|
| 79 |
+
if strings.Compare(fixedCmd[1], expectedFixedCmd[1]) != 0 {
|
| 80 |
+
t.Errorf("Expected %s, got: %s", expectedFixedCmd, fixedCmd)
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
func TestCppifyHeaderIncludes(t *testing.T) {
|
| 85 |
+
t.Setenv("JCC_CPPIFY_PROJECT_HEADERS", "1")
|
| 86 |
+
src := `// Copyright blah
|
| 87 |
+
#include <stddef.h>
|
| 88 |
+
|
| 89 |
+
#include "fuzz.h"
|
| 90 |
+
#include "x/y.h"
|
| 91 |
+
extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
|
| 92 |
+
return 0;
|
| 93 |
+
}`
|
| 94 |
+
newFile, _ := CppifyHeaderIncludes(src)
|
| 95 |
+
expected := `// Copyright blah
|
| 96 |
+
#include <stddef.h>
|
| 97 |
+
|
| 98 |
+
extern "C" {
|
| 99 |
+
#include "fuzz.h"
|
| 100 |
+
}
|
| 101 |
+
extern "C" {
|
| 102 |
+
#include "x/y.h"
|
| 103 |
+
}
|
| 104 |
+
extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
|
| 105 |
+
return 0;
|
| 106 |
+
}
|
| 107 |
+
/* JCCCppifyHeadersMagicString */
|
| 108 |
+
`
|
| 109 |
+
if strings.Compare(newFile, expected) != 0 {
|
| 110 |
+
t.Errorf("Expected: %s, got: %s", expected, newFile)
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
func TestCppifyHeaderIncludesShouldnt(t *testing.T) {
|
| 115 |
+
src := `// Copyright blah
|
| 116 |
+
#include <stddef.h>
|
| 117 |
+
|
| 118 |
+
#include "fuzz.h"
|
| 119 |
+
#include "x/y.h"
|
| 120 |
+
extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
|
| 121 |
+
return 0;
|
| 122 |
+
}`
|
| 123 |
+
newFile, _ := CppifyHeaderIncludes(src)
|
| 124 |
+
if strings.Compare(newFile, src) != 0 {
|
| 125 |
+
t.Errorf("Expected: %s. Got: %s", src, newFile)
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
func TestCppifyHeaderIncludesAlready(t *testing.T) {
|
| 130 |
+
src := `// Copyright blah
|
| 131 |
+
#include <stddef.h>
|
| 132 |
+
|
| 133 |
+
#include "fuzz.h"
|
| 134 |
+
#include "x/y.h"
|
| 135 |
+
extern "C" LLVMFuzzerTestOneInput(uint8_t* data, size_t sz) {
|
| 136 |
+
return 0;
|
| 137 |
+
}
|
| 138 |
+
/* JCCCppifyHeadersMagicString */
|
| 139 |
+
`
|
| 140 |
+
newFile, _ := CppifyHeaderIncludes(src)
|
| 141 |
+
if strings.Compare(newFile, src) != 0 {
|
| 142 |
+
t.Errorf("Expected %s, got: %s", src, newFile)
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
func TestExtractMissingHeaderNonHeaderFailure(t *testing.T) {
|
| 147 |
+
missingHeaderMessage := `clang: error: no such file or directory: 'x'
|
| 148 |
+
clang: error: no input files`
|
| 149 |
+
|
| 150 |
+
header, res := ExtractMissingHeader(missingHeaderMessage)
|
| 151 |
+
if res {
|
| 152 |
+
t.Errorf("Expected no match, got: %s", header)
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
func TestReplaceMissingHeader(t *testing.T) {
|
| 157 |
+
cfile := `// Copyright 2035 Robots
|
| 158 |
+
#include <stddef.h>
|
| 159 |
+
|
| 160 |
+
#include <cstdint>
|
| 161 |
+
|
| 162 |
+
// Some libraries like OpenSSL will use brackets for their own headers.
|
| 163 |
+
#include <missingheader.h>
|
| 164 |
+
|
| 165 |
+
int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) {
|
| 166 |
+
return 0;
|
| 167 |
+
}
|
| 168 |
+
`
|
| 169 |
+
|
| 170 |
+
res := ReplaceMissingHeader(cfile, "missingheader.h", "path/to/includes/missingheader.h")
|
| 171 |
+
expected := `// Copyright 2035 Robots
|
| 172 |
+
#include <stddef.h>
|
| 173 |
+
|
| 174 |
+
#include <cstdint>
|
| 175 |
+
|
| 176 |
+
// Some libraries like OpenSSL will use brackets for their own headers.
|
| 177 |
+
#include "path/to/includes/missingheader.h"
|
| 178 |
+
|
| 179 |
+
int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) {
|
| 180 |
+
return 0;
|
| 181 |
+
}
|
| 182 |
+
`
|
| 183 |
+
if strings.Compare(res, expected) != 0 {
|
| 184 |
+
t.Errorf("Got: %s. Expected: %s.", res, expected)
|
| 185 |
+
}
|
| 186 |
+
}
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jcc-corrected-cfile.c
|
| 2 |
+
jcc-corrected-cfile.cpp
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/jcc/testdata/cfile.c
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-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# pysecsan
|
| 2 |
+
|
| 3 |
+
Security sanitizers for vulnerability detection during runtime.
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pyproject.toml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ["setuptools>=61.0"]
|
| 3 |
+
build-backend = "setuptools.build_meta"
|
| 4 |
+
|
| 5 |
+
[project]
|
| 6 |
+
name = "pysecsan"
|
| 7 |
+
version = "0.1.0"
|
| 8 |
+
authors = [
|
| 9 |
+
{ name="David Korczynski", email="david@adalogics.com" },
|
| 10 |
+
]
|
| 11 |
+
description = "Sanitizers to detect security vulnerabilities at runtime."
|
| 12 |
+
readme = "README.md"
|
| 13 |
+
requires-python = ">=3.7"
|
| 14 |
+
classifiers = [
|
| 15 |
+
"Programming Language :: Python :: 3",
|
| 16 |
+
"License :: OSI Approved :: Apache Software License",
|
| 17 |
+
"Operating System :: OS Independent",
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
[project.urls]
|
| 21 |
+
"Homepage" = "https://github.com/google/oss-fuzz/tree/master/infra/sanitizers/pysecsan"
|
| 22 |
+
"Bug Tracker" = "https://github.com/google/oss-fuzz/issues"
|
local-test-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/pysecsan/yaml_deserialization.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"""Catches vulnerable yaml desrializations that can potentially lead to
|
| 17 |
+
arbitrary code execution."""
|
| 18 |
+
from pysecsan import sanlib
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
import yaml
|
| 22 |
+
# pylint: disable=broad-except
|
| 23 |
+
except Exception:
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def hook_pre_exec_pyyaml_load(stream, loader):
|
| 28 |
+
"""Hook for pyyaml.load_yaml.
|
| 29 |
+
|
| 30 |
+
Exits if the loader is unsafe or vanilla loader and the stream passed
|
| 31 |
+
to the loader is controlled by the fuzz data
|
| 32 |
+
"""
|
| 33 |
+
# Ensure loader is the unsafe loader or vanilla loader
|
| 34 |
+
if loader not in (yaml.loader.Loader, yaml.loader.UnsafeLoader):
|
| 35 |
+
return
|
| 36 |
+
|
| 37 |
+
# Check for exact taint in stream
|
| 38 |
+
if sanlib.is_exact_taint(stream):
|
| 39 |
+
msg = (
|
| 40 |
+
'Yaml deserialization issue.\n'
|
| 41 |
+
'Unsafe deserialization can be used to execute arbitrary commands.\n')
|
| 42 |
+
sanlib.abort_with_issue(msg, 'Yaml deserialisation')
|
local-test-zookeeper-full-01/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-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/infra/base-images/base-builder/sanitizers/pysecsan/tests/subprocess_popen_injection.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 displaying insecure use of subprocess.Popen."""
|
| 16 |
+
|
| 17 |
+
import sys
|
| 18 |
+
import subprocess
|
| 19 |
+
import atheris
|
| 20 |
+
import pysecsan
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def list_files_perhaps(param):
|
| 24 |
+
"""Insecure call to Popen."""
|
| 25 |
+
try:
|
| 26 |
+
subprocess.Popen(' '.join(['ls', '-la', param]), shell=True)
|
| 27 |
+
except ValueError:
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_one_input(data):
|
| 32 |
+
"""Fuzzer entrypoint."""
|
| 33 |
+
fdp = atheris.FuzzedDataProvider(data)
|
| 34 |
+
|
| 35 |
+
if fdp.ConsumeIntInRange(1, 10) == 5:
|
| 36 |
+
list_files_perhaps('FROMFUZZ')
|
| 37 |
+
else:
|
| 38 |
+
list_files_perhaps('.')
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def main():
|
| 42 |
+
"""Set up and start fuzzing."""
|
| 43 |
+
pysecsan.add_hooks()
|
| 44 |
+
|
| 45 |
+
atheris.instrument_all()
|
| 46 |
+
atheris.Setup(sys.argv, test_one_input, enable_python_coverage=True)
|
| 47 |
+
atheris.Fuzz()
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if __name__ == '__main__':
|
| 51 |
+
main()
|
local-test-zookeeper-full-01/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-zookeeper-full-01/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-zookeeper-full-01/fuzz-tooling/infra/base-images/base-clang/checkout_build_install_llvm.sh
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
NPROC=$(nproc)
|
| 19 |
+
|
| 20 |
+
TARGET_TO_BUILD=
|
| 21 |
+
case $(uname -m) in
|
| 22 |
+
x86_64)
|
| 23 |
+
TARGET_TO_BUILD=X86
|
| 24 |
+
ARCHITECTURE_DEPS="g++-multilib"
|
| 25 |
+
# Use chromium's clang revision.
|
| 26 |
+
export CC=$WORK/llvm-stage1/bin/clang
|
| 27 |
+
export CXX=$WORK/llvm-stage1/bin/clang++
|
| 28 |
+
;;
|
| 29 |
+
aarch64)
|
| 30 |
+
TARGET_TO_BUILD=AArch64
|
| 31 |
+
# g++ multilib is not needed on AArch64 because we don't care about i386.
|
| 32 |
+
# We need to install clang and lld using apt because the binary downloaded
|
| 33 |
+
# from Chrome's developer tools doesn't support AArch64.
|
| 34 |
+
# TODO(metzman): Make x86_64 use the distro's clang for consistency once
|
| 35 |
+
# we support AArch64 fully.
|
| 36 |
+
ARCHITECTURE_DEPS="clang lld g++"
|
| 37 |
+
export CC=clang
|
| 38 |
+
export CXX=clang++
|
| 39 |
+
;;
|
| 40 |
+
*)
|
| 41 |
+
echo "Error: unsupported target $(uname -m)"
|
| 42 |
+
exit 1
|
| 43 |
+
;;
|
| 44 |
+
esac
|
| 45 |
+
|
| 46 |
+
INTROSPECTOR_DEP_PACKAGES="texinfo bison flex"
|
| 47 |
+
# zlib1g-dev is needed for llvm-profdata to handle coverage data from rust compiler
|
| 48 |
+
LLVM_DEP_PACKAGES="build-essential make ninja-build git python3 python3-distutils binutils-dev zlib1g-dev $ARCHITECTURE_DEPS $INTROSPECTOR_DEP_PACKAGES"
|
| 49 |
+
|
| 50 |
+
apt-get update && apt-get install -y $LLVM_DEP_PACKAGES --no-install-recommends
|
| 51 |
+
|
| 52 |
+
# For manual bumping.
|
| 53 |
+
# On each bump a full trial run for everything (fuzzing engines, sanitizers,
|
| 54 |
+
# languages, projects, ...) is needed.
|
| 55 |
+
# Check CMAKE_VERSION infra/base-images/base-clang/Dockerfile was released
|
| 56 |
+
# recently enough to fully support this clang version.
|
| 57 |
+
OUR_LLVM_REVISION=llvmorg-18.1.8
|
| 58 |
+
|
| 59 |
+
mkdir $SRC/chromium_tools
|
| 60 |
+
cd $SRC/chromium_tools
|
| 61 |
+
git clone https://chromium.googlesource.com/chromium/src/tools/clang
|
| 62 |
+
cd clang
|
| 63 |
+
# Pin clang script due to https://github.com/google/oss-fuzz/issues/7617
|
| 64 |
+
git checkout 9eb79319239629c1b23cf7a59e5ebb2bab319a34
|
| 65 |
+
|
| 66 |
+
LLVM_SRC=$SRC/llvm-project
|
| 67 |
+
# Checkout
|
| 68 |
+
CHECKOUT_RETRIES=10
|
| 69 |
+
function clone_with_retries {
|
| 70 |
+
REPOSITORY=$1
|
| 71 |
+
LOCAL_PATH=$2
|
| 72 |
+
CHECKOUT_RETURN_CODE=1
|
| 73 |
+
|
| 74 |
+
# Disable exit on error since we might encounter some failures while retrying.
|
| 75 |
+
set +e
|
| 76 |
+
for i in $(seq 1 $CHECKOUT_RETRIES); do
|
| 77 |
+
rm -rf $LOCAL_PATH
|
| 78 |
+
git clone $REPOSITORY $LOCAL_PATH
|
| 79 |
+
CHECKOUT_RETURN_CODE=$?
|
| 80 |
+
if [ $CHECKOUT_RETURN_CODE -eq 0 ]; then
|
| 81 |
+
break
|
| 82 |
+
fi
|
| 83 |
+
done
|
| 84 |
+
|
| 85 |
+
# Re-enable exit on error. If checkout failed, script will exit.
|
| 86 |
+
set -e
|
| 87 |
+
return $CHECKOUT_RETURN_CODE
|
| 88 |
+
}
|
| 89 |
+
clone_with_retries https://github.com/llvm/llvm-project.git $LLVM_SRC
|
| 90 |
+
|
| 91 |
+
git -C $LLVM_SRC checkout $OUR_LLVM_REVISION
|
| 92 |
+
echo "Using LLVM revision: $OUR_LLVM_REVISION"
|
| 93 |
+
|
| 94 |
+
# For fuzz introspector.
|
| 95 |
+
echo "Applying introspector changes"
|
| 96 |
+
OLD_WORKING_DIR=$PWD
|
| 97 |
+
cd $LLVM_SRC
|
| 98 |
+
cp -rf /fuzz-introspector/frontends/llvm/include/llvm/Transforms/FuzzIntrospector/ ./llvm/include/llvm/Transforms/FuzzIntrospector
|
| 99 |
+
cp -rf /fuzz-introspector/frontends/llvm/lib/Transforms/FuzzIntrospector ./llvm/lib/Transforms/FuzzIntrospector
|
| 100 |
+
|
| 101 |
+
# LLVM currently does not support dynamically loading LTO passes. Thus, we
|
| 102 |
+
# hardcode it into Clang instead. Ref: https://reviews.llvm.org/D77704
|
| 103 |
+
/fuzz-introspector/frontends/llvm/patch-llvm.sh
|
| 104 |
+
cd $OLD_WORKING_DIR
|
| 105 |
+
|
| 106 |
+
mkdir -p $WORK/llvm-stage2 $WORK/llvm-stage1
|
| 107 |
+
python3 $SRC/chromium_tools/clang/scripts/update.py --output-dir $WORK/llvm-stage1
|
| 108 |
+
|
| 109 |
+
cd $WORK/llvm-stage2
|
| 110 |
+
cmake -G "Ninja" \
|
| 111 |
+
-DLIBCXX_ENABLE_SHARED=OFF \
|
| 112 |
+
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
|
| 113 |
+
-DLIBCXXABI_ENABLE_SHARED=OFF \
|
| 114 |
+
-DCMAKE_BUILD_TYPE=Release \
|
| 115 |
+
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi" \
|
| 116 |
+
-DLLVM_TARGETS_TO_BUILD="$TARGET_TO_BUILD" \
|
| 117 |
+
-DLLVM_ENABLE_PROJECTS="clang;lld" \
|
| 118 |
+
-DLLVM_BINUTILS_INCDIR="/usr/include/" \
|
| 119 |
+
-DLIBCXXABI_USE_LLVM_UNWINDER=OFF \
|
| 120 |
+
$LLVM_SRC/llvm
|
| 121 |
+
|
| 122 |
+
ninja -j $NPROC
|
| 123 |
+
ninja install
|
| 124 |
+
rm -rf $WORK/llvm-stage1 $WORK/llvm-stage2
|
| 125 |
+
|
| 126 |
+
# libFuzzer sources.
|
| 127 |
+
cp -r $LLVM_SRC/compiler-rt/lib/fuzzer $SRC/libfuzzer
|
| 128 |
+
|
| 129 |
+
# Use the clang we just built from now on.
|
| 130 |
+
export CC=clang
|
| 131 |
+
export CXX=clang++
|
| 132 |
+
|
| 133 |
+
function free_disk_space {
|
| 134 |
+
rm -rf $LLVM_SRC $SRC/chromium_tools
|
| 135 |
+
apt-get autoremove --purge -y $LLVM_DEP_PACKAGES
|
| 136 |
+
# Delete unneeded parts of LLVM to reduce image size.
|
| 137 |
+
# See https://github.com/google/oss-fuzz/issues/5170
|
| 138 |
+
LLVM_TOOLS_TMPDIR=/tmp/llvm-tools
|
| 139 |
+
mkdir $LLVM_TOOLS_TMPDIR
|
| 140 |
+
# Move binaries with llvm- prefix that we want into LLVM_TOOLS_TMPDIR.
|
| 141 |
+
mv \
|
| 142 |
+
/usr/local/bin/llvm-ar \
|
| 143 |
+
/usr/local/bin/llvm-as \
|
| 144 |
+
/usr/local/bin/llvm-config \
|
| 145 |
+
/usr/local/bin/llvm-cov \
|
| 146 |
+
/usr/local/bin/llvm-objcopy \
|
| 147 |
+
/usr/local/bin/llvm-nm \
|
| 148 |
+
/usr/local/bin/llvm-profdata \
|
| 149 |
+
/usr/local/bin/llvm-ranlib \
|
| 150 |
+
/usr/local/bin/llvm-symbolizer \
|
| 151 |
+
/usr/local/bin/llvm-undname \
|
| 152 |
+
$LLVM_TOOLS_TMPDIR
|
| 153 |
+
|
| 154 |
+
# Delete remaining llvm- binaries.
|
| 155 |
+
rm -rf /usr/local/bin/llvm-*
|
| 156 |
+
|
| 157 |
+
# Restore the llvm- binaries we want to keep.
|
| 158 |
+
mv $LLVM_TOOLS_TMPDIR/* /usr/local/bin/
|
| 159 |
+
rm -rf $LLVM_TOOLS_TMPDIR
|
| 160 |
+
|
| 161 |
+
# Remove binaries from LLVM build that we don't need.
|
| 162 |
+
rm -f \
|
| 163 |
+
/usr/local/bin/bugpoint \
|
| 164 |
+
/usr/local/bin/llc \
|
| 165 |
+
/usr/local/bin/lli \
|
| 166 |
+
/usr/local/bin/clang-check \
|
| 167 |
+
/usr/local/bin/clang-refactor \
|
| 168 |
+
/usr/local/bin/clang-offload-wrapper \
|
| 169 |
+
/usr/local/bin/clang-offload-bundler \
|
| 170 |
+
/usr/local/bin/clang-repl \
|
| 171 |
+
/usr/local/bin/clang-check \
|
| 172 |
+
/usr/local/bin/clang-refactor \
|
| 173 |
+
/usr/local/bin/c-index-test \
|
| 174 |
+
/usr/local/bin/clang-rename \
|
| 175 |
+
/usr/local/bin/clang-scan-deps \
|
| 176 |
+
/usr/local/bin/clang-extdef-mapping \
|
| 177 |
+
/usr/local/bin/diagtool \
|
| 178 |
+
/usr/local/bin/sanstats \
|
| 179 |
+
/usr/local/bin/dsymutil \
|
| 180 |
+
/usr/local/bin/verify-uselistorder \
|
| 181 |
+
/usr/local/bin/clang-format
|
| 182 |
+
|
| 183 |
+
# Remove unneeded clang libs, CMake files from LLVM build, lld libs, and the
|
| 184 |
+
# libraries.
|
| 185 |
+
# Note: we need fuzzer_no_main libraries for atheris. Don't delete.
|
| 186 |
+
rm -rf \
|
| 187 |
+
/usr/local/lib/libclang* \
|
| 188 |
+
/usr/local/lib/liblld* \
|
| 189 |
+
/usr/local/lib/cmake/
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
if [ "$TARGET_TO_BUILD" == "AArch64" ]
|
| 193 |
+
then
|
| 194 |
+
free_disk_space
|
| 195 |
+
# Exit now on AArch64. We don't need to rebuild libc++ because on AArch64 we
|
| 196 |
+
# do not support MSAN nor do we care about i386.
|
| 197 |
+
exit 0
|
| 198 |
+
fi
|
| 199 |
+
|
| 200 |
+
function cmake_libcxx {
|
| 201 |
+
extra_args="$@"
|
| 202 |
+
cmake -G "Ninja" \
|
| 203 |
+
-DLIBCXX_ENABLE_SHARED=OFF \
|
| 204 |
+
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
|
| 205 |
+
-DLIBCXXABI_ENABLE_SHARED=OFF \
|
| 206 |
+
-DLIBCXXABI_USE_LLVM_UNWINDER=OFF \
|
| 207 |
+
-DCMAKE_BUILD_TYPE=Release \
|
| 208 |
+
-DLLVM_ENABLE_PIC=ON \
|
| 209 |
+
-DLLVM_TARGETS_TO_BUILD="$TARGET_TO_BUILD" \
|
| 210 |
+
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
|
| 211 |
+
-DLLVM_BINUTILS_INCDIR="/usr/include/" \
|
| 212 |
+
$extra_args \
|
| 213 |
+
-S $LLVM_SRC/runtimes
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
# 32-bit libraries.
|
| 217 |
+
mkdir -p $WORK/i386
|
| 218 |
+
cd $WORK/i386
|
| 219 |
+
cmake_libcxx \
|
| 220 |
+
-DCMAKE_INSTALL_PREFIX=/usr/i386/ \
|
| 221 |
+
-DCMAKE_C_FLAGS="-m32" \
|
| 222 |
+
-DCMAKE_CXX_FLAGS="-m32"
|
| 223 |
+
|
| 224 |
+
ninja -j $NPROC cxx
|
| 225 |
+
ninja install-cxx
|
| 226 |
+
rm -rf $WORK/i386
|
| 227 |
+
|
| 228 |
+
# MemorySanitizer instrumented libraries.
|
| 229 |
+
mkdir -p $WORK/msan
|
| 230 |
+
cd $WORK/msan
|
| 231 |
+
|
| 232 |
+
# https://github.com/google/oss-fuzz/issues/1099
|
| 233 |
+
cat <<EOF > $WORK/msan/ignorelist.txt
|
| 234 |
+
fun:__gxx_personality_*
|
| 235 |
+
EOF
|
| 236 |
+
|
| 237 |
+
cmake_libcxx \
|
| 238 |
+
-DLLVM_USE_SANITIZER=Memory \
|
| 239 |
+
-DCMAKE_INSTALL_PREFIX=/usr/msan/ \
|
| 240 |
+
-DCMAKE_CXX_FLAGS="-fsanitize-ignorelist=$WORK/msan/ignorelist.txt"
|
| 241 |
+
|
| 242 |
+
ninja -j $NPROC cxx
|
| 243 |
+
ninja install-cxx
|
| 244 |
+
rm -rf $WORK/msan
|
| 245 |
+
|
| 246 |
+
free_disk_space
|