From 7b12cff20f56c5b3d7b4b31645c453ff7f617a05 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Fri, 11 Dec 2020 00:19:36 -0500 Subject: [PATCH 1/7] Proof of concept for Bazel support in OSS Fuzz. --- projects/bazel-rules-fuzzing/Dockerfile | 13 +++++++++++ projects/bazel-rules-fuzzing/build.sh | 28 +++++++++++++++++++++++ projects/bazel-rules-fuzzing/project.yaml | 13 +++++++++++ 3 files changed, 54 insertions(+) create mode 100644 projects/bazel-rules-fuzzing/Dockerfile create mode 100644 projects/bazel-rules-fuzzing/build.sh create mode 100644 projects/bazel-rules-fuzzing/project.yaml diff --git a/projects/bazel-rules-fuzzing/Dockerfile b/projects/bazel-rules-fuzzing/Dockerfile new file mode 100644 index 000000000000..e05c68b4d200 --- /dev/null +++ b/projects/bazel-rules-fuzzing/Dockerfile @@ -0,0 +1,13 @@ +FROM gcr.io/oss-fuzz-base/base-builder + +RUN apt-get update && apt-get -y install \ + python wget + +# Install Bazelisk +RUN wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.7.4/bazelisk-linux-amd64 +RUN chmod +x /usr/local/bin/bazel + +# RUN git clone https://github.com/bazelbuild/rules_fuzzing.git -b oss-fuzz-support +COPY local_rules_fuzzing $SRC/rules_fuzzing/ +WORKDIR $SRC/rules_fuzzing/ +COPY build.sh $SRC/ diff --git a/projects/bazel-rules-fuzzing/build.sh b/projects/bazel-rules-fuzzing/build.sh new file mode 100644 index 000000000000..c7d2db6cb1b6 --- /dev/null +++ b/projects/bazel-rules-fuzzing/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash -eu +# +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +declare -r QUERY=' + let all_fuzz_tests = attr(tags, "fuzz-test", "//...") in + $all_fuzz_tests - attr(tags, "no-oss-fuzz", $all_fuzz_tests) +' +declare -r OSS_FUZZ_TESTS="$(bazel query "${QUERY}" | sed 's/$/_oss_fuzz/')" + +bazel build -c opt --config=oss-fuzz --linkopt=-lc++ ${OSS_FUZZ_TESTS[*]} +for oss_fuzz_archive in $(find bazel-bin/ -name '*_oss_fuzz.tar'); do + tar -xvf "${oss_fuzz_archive}" -C "${OUT}" +done diff --git a/projects/bazel-rules-fuzzing/project.yaml b/projects/bazel-rules-fuzzing/project.yaml new file mode 100644 index 000000000000..244b2822ff7f --- /dev/null +++ b/projects/bazel-rules-fuzzing/project.yaml @@ -0,0 +1,13 @@ +homepage: "https://github.com/bazelbuild/rules_fuzzing" +language: c++ +primary_contact: "sbucur@google.com" +fuzzing_engines: + - libfuzzer + - afl + - honggfuzz + - dataflow +sanitizers: + - address + - undefined + - memory + - dataflow \ No newline at end of file From 337be0af2c5d1c59832b9d68ec6e17e8f66e9071 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Fri, 8 Jan 2021 10:04:08 -0500 Subject: [PATCH 2/7] Moved the Bazel rules project under a directory with a "-test" suffix, to better convey intent. --- .../Dockerfile | 3 +-- .../build.sh | 0 .../project.yaml | 9 +++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) rename projects/{bazel-rules-fuzzing => bazel-rules-fuzzing-test}/Dockerfile (71%) rename projects/{bazel-rules-fuzzing => bazel-rules-fuzzing-test}/build.sh (100%) rename projects/{bazel-rules-fuzzing => bazel-rules-fuzzing-test}/project.yaml (66%) diff --git a/projects/bazel-rules-fuzzing/Dockerfile b/projects/bazel-rules-fuzzing-test/Dockerfile similarity index 71% rename from projects/bazel-rules-fuzzing/Dockerfile rename to projects/bazel-rules-fuzzing-test/Dockerfile index e05c68b4d200..54be0a0c436a 100644 --- a/projects/bazel-rules-fuzzing/Dockerfile +++ b/projects/bazel-rules-fuzzing-test/Dockerfile @@ -7,7 +7,6 @@ RUN apt-get update && apt-get -y install \ RUN wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.7.4/bazelisk-linux-amd64 RUN chmod +x /usr/local/bin/bazel -# RUN git clone https://github.com/bazelbuild/rules_fuzzing.git -b oss-fuzz-support -COPY local_rules_fuzzing $SRC/rules_fuzzing/ +RUN git clone https://github.com/bazelbuild/rules_fuzzing.git WORKDIR $SRC/rules_fuzzing/ COPY build.sh $SRC/ diff --git a/projects/bazel-rules-fuzzing/build.sh b/projects/bazel-rules-fuzzing-test/build.sh similarity index 100% rename from projects/bazel-rules-fuzzing/build.sh rename to projects/bazel-rules-fuzzing-test/build.sh diff --git a/projects/bazel-rules-fuzzing/project.yaml b/projects/bazel-rules-fuzzing-test/project.yaml similarity index 66% rename from projects/bazel-rules-fuzzing/project.yaml rename to projects/bazel-rules-fuzzing-test/project.yaml index 244b2822ff7f..99b1786c5c7e 100644 --- a/projects/bazel-rules-fuzzing/project.yaml +++ b/projects/bazel-rules-fuzzing-test/project.yaml @@ -1,13 +1,18 @@ homepage: "https://github.com/bazelbuild/rules_fuzzing" language: c++ -primary_contact: "sbucur@google.com" + +# This is a test project. +disabled: true +primary_contact: "test@example.com" + fuzzing_engines: - libfuzzer - afl - honggfuzz - dataflow + sanitizers: - address - undefined - memory - - dataflow \ No newline at end of file + - dataflow From 18f07dbf0f08eb32bb3f533bb15d5fe8d4e207b3 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Fri, 8 Jan 2021 10:05:46 -0500 Subject: [PATCH 3/7] Added copyright header. --- projects/bazel-rules-fuzzing-test/Dockerfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/projects/bazel-rules-fuzzing-test/Dockerfile b/projects/bazel-rules-fuzzing-test/Dockerfile index 54be0a0c436a..ba48cf504d4c 100644 --- a/projects/bazel-rules-fuzzing-test/Dockerfile +++ b/projects/bazel-rules-fuzzing-test/Dockerfile @@ -1,3 +1,19 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + FROM gcr.io/oss-fuzz-base/base-builder RUN apt-get update && apt-get -y install \ From bd9b8e7c4e33c08633d214735c8f7ee09656c0d7 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Thu, 14 Jan 2021 20:52:16 -0500 Subject: [PATCH 4/7] Update year in copyright note. --- projects/bazel-rules-fuzzing-test/Dockerfile | 2 +- projects/bazel-rules-fuzzing-test/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/bazel-rules-fuzzing-test/Dockerfile b/projects/bazel-rules-fuzzing-test/Dockerfile index ba48cf504d4c..9a2047ea424b 100644 --- a/projects/bazel-rules-fuzzing-test/Dockerfile +++ b/projects/bazel-rules-fuzzing-test/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2020 Google LLC +# Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/projects/bazel-rules-fuzzing-test/build.sh b/projects/bazel-rules-fuzzing-test/build.sh index c7d2db6cb1b6..b11b055bc912 100644 --- a/projects/bazel-rules-fuzzing-test/build.sh +++ b/projects/bazel-rules-fuzzing-test/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -eu # -# Copyright 2020 Google LLC +# Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 326f4540e77b640ae239e03a69d20bb38c39d770 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Thu, 14 Jan 2021 21:18:52 -0500 Subject: [PATCH 5/7] Factor out the '_oss_fuzz' package suffix to bash var. --- projects/bazel-rules-fuzzing-test/build.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/bazel-rules-fuzzing-test/build.sh b/projects/bazel-rules-fuzzing-test/build.sh index b11b055bc912..f61f7c86c568 100644 --- a/projects/bazel-rules-fuzzing-test/build.sh +++ b/projects/bazel-rules-fuzzing-test/build.sh @@ -20,9 +20,10 @@ declare -r QUERY=' let all_fuzz_tests = attr(tags, "fuzz-test", "//...") in $all_fuzz_tests - attr(tags, "no-oss-fuzz", $all_fuzz_tests) ' -declare -r OSS_FUZZ_TESTS="$(bazel query "${QUERY}" | sed 's/$/_oss_fuzz/')" +declare -r PACKAGE_SUFFIX="_oss_fuzz" +declare -r OSS_FUZZ_TESTS="$(bazel query "${QUERY}" | sed "s/$/${PACKAGE_SUFFIX}/")" bazel build -c opt --config=oss-fuzz --linkopt=-lc++ ${OSS_FUZZ_TESTS[*]} -for oss_fuzz_archive in $(find bazel-bin/ -name '*_oss_fuzz.tar'); do +for oss_fuzz_archive in $(find bazel-bin/ -name "*${PACKAGE_SUFFIX}.tar"); do tar -xvf "${oss_fuzz_archive}" -C "${OUT}" done From fc206044b0b6560d5ce68b12d35cc634e3caec2d Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Thu, 14 Jan 2021 21:19:44 -0500 Subject: [PATCH 6/7] Moving 'disabled' attribute at the end of the yaml file. --- projects/bazel-rules-fuzzing-test/project.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/bazel-rules-fuzzing-test/project.yaml b/projects/bazel-rules-fuzzing-test/project.yaml index 99b1786c5c7e..ecb68c69b78d 100644 --- a/projects/bazel-rules-fuzzing-test/project.yaml +++ b/projects/bazel-rules-fuzzing-test/project.yaml @@ -1,8 +1,5 @@ homepage: "https://github.com/bazelbuild/rules_fuzzing" language: c++ - -# This is a test project. -disabled: true primary_contact: "test@example.com" fuzzing_engines: @@ -16,3 +13,6 @@ sanitizers: - undefined - memory - dataflow + +# This is a test project. +disabled: true From c284ed95d1c5ac30af2c92445e5d03c31162b5f2 Mon Sep 17 00:00:00 2001 From: Stefan Bucur Date: Thu, 21 Jan 2021 17:34:56 -0500 Subject: [PATCH 7/7] Simplified Dockerfile due to base image update. --- projects/bazel-rules-fuzzing-test/Dockerfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/projects/bazel-rules-fuzzing-test/Dockerfile b/projects/bazel-rules-fuzzing-test/Dockerfile index 9a2047ea424b..c007f5aa85ed 100644 --- a/projects/bazel-rules-fuzzing-test/Dockerfile +++ b/projects/bazel-rules-fuzzing-test/Dockerfile @@ -16,13 +16,6 @@ FROM gcr.io/oss-fuzz-base/base-builder -RUN apt-get update && apt-get -y install \ - python wget - -# Install Bazelisk -RUN wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.7.4/bazelisk-linux-amd64 -RUN chmod +x /usr/local/bin/bazel - RUN git clone https://github.com/bazelbuild/rules_fuzzing.git WORKDIR $SRC/rules_fuzzing/ COPY build.sh $SRC/