diff options
-rw-r--r-- | BUILD | 37 | ||||
-rw-r--r-- | bazel/build_defs.bzl | 6 | ||||
-rw-r--r-- | bazel/upb_proto_library.bzl | 16 | ||||
-rw-r--r-- | tests/corpus/README | 1 | ||||
-rw-r--r-- | tests/corpus/temp.cc | 1 | ||||
-rw-r--r-- | tests/file_descriptor_parsenew_fuzzer.cc | 15 | ||||
-rwxr-xr-x | tools/make_cmakelists.py | 6 |
7 files changed, 61 insertions, 21 deletions
@@ -9,7 +9,6 @@ load( "make_shell_script", "upb_amalgamation", ) - load( "//bazel:upb_proto_library.bzl", "upb_proto_library", @@ -43,6 +42,11 @@ config_setting( visibility = ["//visibility:public"], ) +config_setting( + name = "fuzz", + values = {"define": "fuzz=true"}, +) + # Public C/C++ libraries ####################################################### cc_library( @@ -76,23 +80,23 @@ cc_library( # give up any backward compatibility guarantees. cc_library( name = "generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", - textual_hdrs = [ - "upb/port_def.inc", - "upb/port_undef.inc", - ], hdrs = [ "upb/generated_util.h", "upb/msg.h", ], - deps = [":upb"], copts = COPTS, + textual_hdrs = [ + "upb/port_def.inc", + "upb/port_undef.inc", + ], visibility = ["//visibility:public"], + deps = [":upb"], ) upb_proto_library( name = "descriptor_upbproto", - deps = ["@com_google_protobuf//:descriptor_proto"], visibility = ["//visibility:public"], + deps = ["@com_google_protobuf//:descriptor_proto"], ) cc_library( @@ -356,6 +360,25 @@ cc_test( ], ) +# OSS-Fuzz test +cc_binary( + name = "file_descriptor_parsenew_fuzzer", + testonly = 1, + srcs = ["tests/file_descriptor_parsenew_fuzzer.cc"], + copts = CPPOPTS + select({ + "//conditions:default": [], + ":fuzz": ["-fsanitize=fuzzer,address"], + }), + defines = select({ + "//conditions:default": [], + ":fuzz": ["HAVE_FUZZER"], + }), + deps = [ + ":descriptor_upbproto", + ":upb", + ], +) + # copybara:strip_for_google3_begin upb_proto_reflection_library( name = "descriptor_upbreflection", diff --git a/bazel/build_defs.bzl b/bazel/build_defs.bzl index 1ec80b3..08bb44e 100644 --- a/bazel/build_defs.bzl +++ b/bazel/build_defs.bzl @@ -1,6 +1,6 @@ """Internal rules for building upb.""" -load(":upb_proto_library.bzl", "GeneratedSrcs") +load(":upb_proto_library.bzl", "GeneratedSrcsInfo") def _librule(name): return name + "_lib" @@ -173,8 +173,8 @@ SrcList = provider( ) def _file_list_aspect_impl(target, ctx): - if GeneratedSrcs in target: - srcs = target[GeneratedSrcs] + if GeneratedSrcsInfo in target: + srcs = target[GeneratedSrcsInfo] return [SrcList(srcs = srcs.srcs + srcs.hdrs)] srcs = [] diff --git a/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl index 503925e..d62770b 100644 --- a/bazel/upb_proto_library.bzl +++ b/bazel/upb_proto_library.bzl @@ -134,7 +134,7 @@ def _cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): # upb_proto_library / upb_proto_reflection_library shared code ################# -GeneratedSrcs = provider( +GeneratedSrcsInfo = provider( fields = { "srcs": "list of srcs", "hdrs": "list of hdrs", @@ -142,7 +142,7 @@ GeneratedSrcs = provider( ) _WrappedCcInfo = provider(fields = ["cc_info"]) -_WrappedGeneratedSrcs = provider(fields = ["srcs"]) +_WrappedGeneratedSrcsInfo = provider(fields = ["srcs"]) def _compile_upb_protos(ctx, proto_info, proto_sources, ext): srcs = [_generate_output_file(ctx, name, ext + ".c") for name in proto_sources] @@ -164,18 +164,18 @@ def _compile_upb_protos(ctx, proto_info, proto_sources, ext): [_get_real_short_path(file) for file in proto_sources], progress_message = "Generating upb protos for :" + ctx.label.name, ) - return GeneratedSrcs(srcs = srcs, hdrs = hdrs) + return GeneratedSrcsInfo(srcs = srcs, hdrs = hdrs) def _upb_proto_rule_impl(ctx): if len(ctx.attr.deps) != 1: fail("only one deps dependency allowed.") dep = ctx.attr.deps[0] - if _WrappedCcInfo not in dep or _WrappedGeneratedSrcs not in dep: + if _WrappedCcInfo not in dep or _WrappedGeneratedSrcsInfo not in dep: fail("proto_library rule must generate _WrappedCcInfo and " + - "_WrappedGeneratedSrcs (aspect should have handled this).") + "_WrappedGeneratedSrcsInfo (aspect should have handled this).") cc_info = dep[_WrappedCcInfo].cc_info - srcs = dep[_WrappedGeneratedSrcs].srcs - lib = cc_info.linking_context.libraries_to_link[0] + srcs = dep[_WrappedGeneratedSrcsInfo].srcs + lib = cc_info.linking_context.libraries_to_link.to_list()[0] files = _filter_none([ lib.static_library, lib.pic_static_library, @@ -200,7 +200,7 @@ def _upb_proto_aspect_impl(target, ctx): srcs = files.srcs, dep_ccinfos = dep_ccinfos, ) - return [_WrappedCcInfo(cc_info = cc_info), _WrappedGeneratedSrcs(srcs = files)] + return [_WrappedCcInfo(cc_info = cc_info), _WrappedGeneratedSrcsInfo(srcs = files)] def _maybe_add(d): if not _is_bazel: diff --git a/tests/corpus/README b/tests/corpus/README new file mode 100644 index 0000000..9bd8f1e --- /dev/null +++ b/tests/corpus/README @@ -0,0 +1 @@ +Corpus folder for fuzzing diff --git a/tests/corpus/temp.cc b/tests/corpus/temp.cc new file mode 100644 index 0000000..2bf1160 --- /dev/null +++ b/tests/corpus/temp.cc @@ -0,0 +1 @@ +// Hello World diff --git a/tests/file_descriptor_parsenew_fuzzer.cc b/tests/file_descriptor_parsenew_fuzzer.cc new file mode 100644 index 0000000..057e62d --- /dev/null +++ b/tests/file_descriptor_parsenew_fuzzer.cc @@ -0,0 +1,15 @@ +#include <cstdint> + +#include "google/protobuf/descriptor.upb.h" +#include "upb/upb.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + upb::Arena arena; + google_protobuf_FileDescriptorProto_parse(reinterpret_cast<const char*>(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 22f3757..a4923c8 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()) |