Build fixes from fuzz target.

pull/13171/head
Joshua Haberman 6 years ago
parent 6ce5e722f1
commit 493e9b2614
  1. 18
      BUILD
  2. 2
      bazel/upb_proto_library.bzl
  3. 13
      tests/file_descriptor_parsenew_fuzzer.cc
  4. 6
      tools/make_cmakelists.py

18
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",
],
)

@ -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,

@ -1,16 +1,15 @@
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#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<const char*>(data), size);
upb::Arena arena;
google_protobuf_FileDescriptorProto_parsenew(strview, arena.ptr());
google_protobuf_FileDescriptorProto_parse(reinterpret_cast<const char*>(data),
size, arena.ptr());
return 0;
}
#ifndef HAVE_FUZZER
int main() {}
#endif

@ -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())

Loading…
Cancel
Save