From 03c5df4096a52e23422172eda3742778ccd82c29 Mon Sep 17 00:00:00 2001 From: Asra Ali Date: Wed, 7 Aug 2019 11:42:29 -0400 Subject: [PATCH 1/3] fuzz: add xxhash utility fuzzer Signed-off-by: Asra Ali --- test/common/common/BUILD | 9 +++++++ test/common/common/hash_corpus/example | 1 + test/common/common/hash_fuzz_test.cc | 34 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/common/common/hash_corpus/example create mode 100644 test/common/common/hash_fuzz_test.cc diff --git a/test/common/common/BUILD b/test/common/common/BUILD index d72fea4b65215..304387d730769 100644 --- a/test/common/common/BUILD +++ b/test/common/common/BUILD @@ -55,6 +55,15 @@ envoy_cc_fuzz_test( deps = ["//source/common/common:utility_lib"], ) +envoy_cc_fuzz_test( + name = "hash_fuzz_test", + srcs = ["hash_fuzz_test.cc"], + corpus = "hash_corpus", + # Fuzzer is stable, no bugs, simple test target; avoid emitting CO2. + tags = ["no_fuzz"], + deps = ["//source/common/common:hash_lib"], +) + envoy_cc_test( name = "cleanup_test", srcs = ["cleanup_test.cc"], diff --git a/test/common/common/hash_corpus/example b/test/common/common/hash_corpus/example new file mode 100644 index 0000000000000..95d09f2b10159 --- /dev/null +++ b/test/common/common/hash_corpus/example @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/test/common/common/hash_fuzz_test.cc b/test/common/common/hash_fuzz_test.cc new file mode 100644 index 0000000000000..c003fc495df92 --- /dev/null +++ b/test/common/common/hash_fuzz_test.cc @@ -0,0 +1,34 @@ +#include "common/common/hash.h" + +#include "test/fuzz/fuzz_runner.h" +#include "absl/strings/string_view.h" + +namespace Envoy { +namespace Fuzz { +namespace { + +DEFINE_FUZZER(const uint8_t* buf, size_t len) { + const std::string input(reinterpret_cast(buf), len); + { + HashUtil::xxHash64(input); + } + { + HashUtil::djb2CaseInsensitiveHash(input); + } + { + MurmurHash::murmurHash2_64(input); + } + if (len > 0) { + // Split the input string into two parts to make a key-value pair. + const size_t split_point = *reinterpret_cast(buf) % len; + const std::string key = input.substr(0, split_point); + const std::string value = input.substr(split_point); + StringMap map; + map[key] = value; + map.find(key); + } +} + +} // namespace +} // namespace Fuzz +} // namespace Envoy From e9930245f81ef6f45dfbef5d42bbcb044ebc1606 Mon Sep 17 00:00:00 2001 From: Asra Ali Date: Wed, 7 Aug 2019 11:43:08 -0400 Subject: [PATCH 2/3] format Signed-off-by: Asra Ali format Signed-off-by: Asra Ali --- test/common/common/hash_fuzz_test.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/common/common/hash_fuzz_test.cc b/test/common/common/hash_fuzz_test.cc index c003fc495df92..a4b3f6c032a30 100644 --- a/test/common/common/hash_fuzz_test.cc +++ b/test/common/common/hash_fuzz_test.cc @@ -1,6 +1,7 @@ #include "common/common/hash.h" #include "test/fuzz/fuzz_runner.h" + #include "absl/strings/string_view.h" namespace Envoy { @@ -9,15 +10,9 @@ namespace { DEFINE_FUZZER(const uint8_t* buf, size_t len) { const std::string input(reinterpret_cast(buf), len); - { - HashUtil::xxHash64(input); - } - { - HashUtil::djb2CaseInsensitiveHash(input); - } - { - MurmurHash::murmurHash2_64(input); - } + { HashUtil::xxHash64(input); } + { HashUtil::djb2CaseInsensitiveHash(input); } + { MurmurHash::murmurHash2_64(input); } if (len > 0) { // Split the input string into two parts to make a key-value pair. const size_t split_point = *reinterpret_cast(buf) % len; From 088c2d9f411780eef3127228e74954f12bdf0cc2 Mon Sep 17 00:00:00 2001 From: Asra Ali Date: Fri, 9 Aug 2019 15:13:35 -0400 Subject: [PATCH 3/3] remove no fuzz tag Signed-off-by: Asra Ali --- test/common/common/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/common/common/BUILD b/test/common/common/BUILD index 304387d730769..4714f1ff5c721 100644 --- a/test/common/common/BUILD +++ b/test/common/common/BUILD @@ -59,8 +59,6 @@ envoy_cc_fuzz_test( name = "hash_fuzz_test", srcs = ["hash_fuzz_test.cc"], corpus = "hash_corpus", - # Fuzzer is stable, no bugs, simple test target; avoid emitting CO2. - tags = ["no_fuzz"], deps = ["//source/common/common:hash_lib"], )