diff --git a/BUILD b/BUILD index 1fbdda4e64..9913e9199a 100644 --- a/BUILD +++ b/BUILD @@ -43,6 +43,11 @@ config_setting( visibility = ["//visibility:public"], ) +config_setting( + name = "fuzz", + values = {"define": "fuzz=true"}, +) + # Public C/C++ libraries ####################################################### cc_library( @@ -358,15 +363,20 @@ cc_test( # OSS-Fuzz test cc_binary( + testonly = 1, name = "file_descriptor_parsenew_fuzzer", srcs = ["tests/file_descriptor_parsenew_fuzzer.cc"], - copts = CPPOTS + ["-fsanitizer=fuzzer,address"], + copts = CPPOPTS + select({ + "//conditions:default": [], + ":fuzz": ["-fsanitizer=fuzzer,address"], + }), + defines = select({ + "//conditions:default": [], + ":fuzz": ["HAVE_FUZZER"], + }), deps = [ ":descriptor_upbproto", - ":descriptor_upbreflection", ":upb", - ":upb_pb", - ":upb_test", ], ) diff --git a/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl index 503925e8ac..bf2e33ad6f 100644 --- a/bazel/upb_proto_library.bzl +++ b/bazel/upb_proto_library.bzl @@ -175,7 +175,7 @@ def _upb_proto_rule_impl(ctx): "_WrappedGeneratedSrcs (aspect should have handled this).") cc_info = dep[_WrappedCcInfo].cc_info srcs = dep[_WrappedGeneratedSrcs].srcs - lib = cc_info.linking_context.libraries_to_link[0] + lib = cc_info.linking_context.libraries_to_link.to_list()[0] files = _filter_none([ lib.static_library, lib.pic_static_library, diff --git a/tests/file_descriptor_parsenew_fuzzer.cc b/tests/file_descriptor_parsenew_fuzzer.cc index 41664690ea..057e62d8bf 100644 --- a/tests/file_descriptor_parsenew_fuzzer.cc +++ b/tests/file_descriptor_parsenew_fuzzer.cc @@ -1,16 +1,15 @@ -#include #include -#include #include "google/protobuf/descriptor.upb.h" -#include "upb/def.h" -#include "upb/msg.h" #include "upb/upb.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - upb_strview strview = - upb_strview_make(reinterpret_cast(data), size); upb::Arena arena; - google_protobuf_FileDescriptorProto_parsenew(strview, arena.ptr()); + google_protobuf_FileDescriptorProto_parse(reinterpret_cast(data), + size, arena.ptr()); return 0; } + +#ifndef HAVE_FUZZER +int main() {} +#endif diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index 22f3757155..a4923c8da0 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -48,7 +48,7 @@ class BuildFileFunctions(object): else: print("Warning: no such file: " + file) - if filter(IsSourceFile, files): + if list(filter(IsSourceFile, files)): # Has sources, make this a normal library. self.converter.toplevel += "add_library(%s\n %s)\n" % ( kwargs["name"], @@ -272,8 +272,8 @@ def GetDict(obj): globs = GetDict(converter) -execfile("WORKSPACE", GetDict(WorkspaceFileFunctions(converter))) -execfile("BUILD", GetDict(BuildFileFunctions(converter))) +exec(open("WORKSPACE").read(), GetDict(WorkspaceFileFunctions(converter))) +exec(open("BUILD").read(), GetDict(BuildFileFunctions(converter))) with open(sys.argv[1], "w") as f: f.write(converter.convert())