summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-06-17 12:50:45 -0700
committerJoshua Haberman <jhaberman@gmail.com>2019-06-17 12:50:45 -0700
commit493e9b2614df79728deb40d5ec91edefa91a89c7 (patch)
treef504e94c0a5b4784b5786241e57b2423b6e7f71a
parent6ce5e722f16e74deff65db87eb1244f4396b2832 (diff)
Build fixes from fuzz target.
-rw-r--r--BUILD18
-rw-r--r--bazel/upb_proto_library.bzl2
-rw-r--r--tests/file_descriptor_parsenew_fuzzer.cc13
-rwxr-xr-xtools/make_cmakelists.py6
4 files changed, 24 insertions, 15 deletions
diff --git a/BUILD b/BUILD
index 1fbdda4..9913e91 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 503925e..bf2e33a 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 4166469..057e62d 100644
--- a/tests/file_descriptor_parsenew_fuzzer.cc
+++ b/tests/file_descriptor_parsenew_fuzzer.cc
@@ -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
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())
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback