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

[json] enable new JSON in fuzzer #15103

Merged
merged 2 commits into from
Feb 19, 2021
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
1 change: 1 addition & 0 deletions test/common/json/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ envoy_cc_fuzz_test(
"//source/common/protobuf",
"//source/common/protobuf:utility_lib",
"//test/fuzz:utility_lib",
"//test/test_common:test_runtime_lib",
"//test/test_common:utility_lib",
],
)
Expand Down
12 changes: 8 additions & 4 deletions test/common/json/json_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@

#include "test/fuzz/fuzz_runner.h"
#include "test/fuzz/utility.h"
#include "test/test_common/test_runtime.h"
#include "test/test_common/utility.h"

namespace Envoy {
namespace Fuzz {

// We have multiple third party JSON parsers in Envoy, both RapidJSON and Protobuf.
// We only fuzz protobuf today, since RapidJSON is deprecated and has known
// limitations when we have deeply nested structures. Do not use RapidJSON for
// anything new in Envoy! See https://github.com/envoyproxy/envoy/issues/4705.
// We have multiple third party JSON parsers in Envoy, nlohmann/JSON, RapidJSON and Protobuf.
// We fuzz nlohmann/JSON and protobuf and compare their results, since RapidJSON is deprecated and
// has known limitations. See https://github.com/envoyproxy/envoy/issues/4705.
DEFINE_FUZZER(const uint8_t* buf, size_t len) {
TestScopedRuntime runtime;
Runtime::LoaderSingleton::getExisting()->mergeValues(
{{"envoy.reloadable_features.remove_legacy_json", "true"}});

std::string json_string{reinterpret_cast<const char*>(buf), len};

// Load via Protobuf JSON parsing, if we can.
Expand Down