From b53730dbd9dbc51cf0166786482a6ccd38482248 Mon Sep 17 00:00:00 2001 From: asraa Date: Fri, 19 Feb 2021 02:12:06 -0500 Subject: [PATCH] enable new JSON in fuzzer (#15103) Signed-off-by: Asra Ali --- test/common/json/BUILD | 1 + test/common/json/json_fuzz_test.cc | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/common/json/BUILD b/test/common/json/BUILD index 83bf67d96ad0..b77f0b53d88a 100644 --- a/test/common/json/BUILD +++ b/test/common/json/BUILD @@ -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", ], ) diff --git a/test/common/json/json_fuzz_test.cc b/test/common/json/json_fuzz_test.cc index b85742c2c14f..03c298528bd0 100644 --- a/test/common/json/json_fuzz_test.cc +++ b/test/common/json/json_fuzz_test.cc @@ -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(buf), len}; // Load via Protobuf JSON parsing, if we can.