Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz: utility fuzz test #3493

Merged
merged 5 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ envoy_cc_fuzz_test(
deps = ["//source/common/common:base64_lib"],
)

envoy_cc_fuzz_test(
name = "utility_fuzz_test",
srcs = ["utility_fuzz_test.cc"],
corpus = "utility_corpus",
deps = ["//source/common/common:utility_lib"],
)

envoy_cc_test(
name = "cleanup_test",
srcs = ["cleanup_test.cc"],
Expand Down
1 change: 1 addition & 0 deletions test/common/common/utility_corpus/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
63 changes: 63 additions & 0 deletions test/common/common/utility_fuzz_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "common/common/utility.h"

#include "test/fuzz/fuzz_runner.h"

#include "absl/strings/string_view.h"

namespace Envoy {
namespace Fuzz {

DEFINE_FUZZER(const uint8_t* buf, size_t len) {
{
uint64_t out;
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::atoul(string_buffer.c_str(), out);
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::escape(string_buffer);
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::toUpper(string_buffer);
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::trim(string_buffer);
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::ltrim(string_buffer);
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::rtrim(string_buffer);
}
if (len > 0) {
const size_t split_point = *reinterpret_cast<const uint8_t*>(buf) % len;
// (string_buffer.substr(0, split_point), string_buffer.substr(split_point))
// @param1: substring of buffer from beginning to split_point
// @param2: substring of buffer from split_point to end of the string
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::endsWith(string_buffer.substr(0, split_point), string_buffer.substr(split_point));
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::caseCompare(string_buffer.substr(0, split_point),
string_buffer.substr(split_point));
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::cropLeft(string_buffer.substr(0, split_point), string_buffer.substr(split_point));
}
{
const std::string string_buffer(reinterpret_cast<const char*>(buf), len);
StringUtil::cropRight(string_buffer.substr(0, split_point),
string_buffer.substr(split_point));
}
}
}

} // namespace Fuzz
} // namespace Envoy