Skip to content

Commit

Permalink
enable new JSON in fuzzer (envoyproxy#15103)
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <[email protected]>
  • Loading branch information
asraa authored Feb 19, 2021
1 parent 6f1ba43 commit b53730d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit b53730d

Please sign in to comment.