diff options
author | Norbert Schneider <norbert.schneider@code-intelligence.com> | 2023-05-16 10:44:32 +0200 |
---|---|---|
committer | Norbert Schneider <mail@bertschneider.de> | 2023-05-19 16:17:07 +0200 |
commit | 4d7fcaaf185851a2983ebd4e380bc814622023cb (patch) | |
tree | ae2a12ff2b2317706b9e86c06b53572e3de2636d | |
parent | 19385ed86d587c532a8a540ec6f5197090ddfbb5 (diff) | |
download | jazzer-api-4d7fcaaf185851a2983ebd4e380bc814622023cb.tar.gz |
mutator: Add libprotobuf-mutator test to compare implementations
-rw-r--r-- | WORKSPACE.bazel | 24 | ||||
-rw-r--r-- | src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/BUILD.bazel | 9 | ||||
-rw-r--r-- | src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/proto2.proto | 1 | ||||
-rw-r--r-- | tests/BUILD.bazel | 14 | ||||
-rw-r--r-- | tests/src/test/cc/complex_proto_fuzzer.cc | 22 |
5 files changed, 70 insertions, 0 deletions
diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 34b45531..b53d7b78 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -267,3 +267,27 @@ http_file( "https://github.com/CodeIntelligenceTesting/addlicense/releases/download/v1.1.1/addlicense-linux-amd64", ], ) + +http_archive( + name = "libprotobuf-mutator", + build_file_content = """ +cc_library( + name = "libprotobuf-mutator", + srcs = glob([ + "src/*.cc", + "src/*.h", + "src/libfuzzer/*.cc", + "src/libfuzzer/*.h", + "port/protobuf.h", + ], exclude = [ + "**/*_test.cc", + ]), + hdrs = ["src/libfuzzer/libfuzzer_macro.h"], + deps = ["@com_google_protobuf//:protobuf"], + visibility = ["//visibility:public"], +) +""", + sha256 = "fd299fd72c5cf664259d9bd43a72cb74dc6a8b9604d107fe2d2e90885aeb7c16", + strip_prefix = "libprotobuf-mutator-1.1", + urls = ["https://github.com/google/libprotobuf-mutator/archive/refs/tags/v1.1.tar.gz"], +) diff --git a/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/BUILD.bazel b/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/BUILD.bazel index 520d0d1b..bf8b551d 100644 --- a/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/BUILD.bazel +++ b/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/BUILD.bazel @@ -30,6 +30,15 @@ java_proto_library( deps = [":proto2_proto"], ) +cc_proto_library( + name = "proto2_cc_proto", + testonly = True, + visibility = [ + "//tests:__pkg__", + ], + deps = [":proto2_proto"], +) + java_test_suite( name = "ProtoTests", size = "small", diff --git a/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/proto2.proto b/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/proto2.proto index a3d563d8..77dbb5e8 100644 --- a/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/proto2.proto +++ b/src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/proto2.proto @@ -14,6 +14,7 @@ syntax = "proto2"; +package com.code_intelligence.jazzer.protobuf; option java_package = "com.code_intelligence.jazzer.protobuf"; message PrimitiveField2 { diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index 4cbc9a19..b0e88452 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -472,6 +472,20 @@ java_fuzz_target_test( ], ) +cc_binary( + name = "complex_proto_fuzzer", + testonly = True, + srcs = ["src/test/cc/complex_proto_fuzzer.cc"], + copts = ["-fsanitize=fuzzer"], + linkopts = ["-fsanitize=fuzzer"], + # libfuzzer not shipped on macOS. + target_compatible_with = LINUX_ONLY, + deps = [ + "//src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto:proto2_cc_proto", + "@libprotobuf-mutator", + ], +) + java_fuzz_target_test( name = "ExperimentalMutatorDynamicProtoFuzzer", srcs = ["src/test/java/com/example/ExperimentalMutatorDynamicProtoFuzzer.java"], diff --git a/tests/src/test/cc/complex_proto_fuzzer.cc b/tests/src/test/cc/complex_proto_fuzzer.cc new file mode 100644 index 00000000..b9eea8bb --- /dev/null +++ b/tests/src/test/cc/complex_proto_fuzzer.cc @@ -0,0 +1,22 @@ +// Copyright 2023 Code Intelligence GmbH +// +// 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. + +#include "src/libfuzzer/libfuzzer_macro.h" +#include "src/test/java/com/code_intelligence/jazzer/mutation/mutator/proto/proto2.pb.h" + +DEFINE_PROTO_FUZZER(const com::code_intelligence::jazzer::protobuf::TestProtobuf& proto) { + if (proto.i32() == 1234 && proto.str() == "abcd") { + abort(); + } +} |