From 59dbdfeea28e0a6ea2d4cf36bb6ea8170f93afc3 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 15 May 2023 13:21:37 -0700 Subject: [PATCH] [xds_client_fuzzer] fail bootstrap parsing if xds_servers is empty (#33119) b/269022924 --- src/core/ext/xds/xds_bootstrap_grpc.cc | 7 +++++++ test/core/xds/xds_bootstrap_test.cc | 13 +++++++++++++ .../xds_client_corpora/bootstrap_xds_servers_empty | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/core/xds/xds_client_corpora/bootstrap_xds_servers_empty diff --git a/src/core/ext/xds/xds_bootstrap_grpc.cc b/src/core/ext/xds/xds_bootstrap_grpc.cc index 16676fda584..52e8b31d7ae 100644 --- a/src/core/ext/xds/xds_bootstrap_grpc.cc +++ b/src/core/ext/xds/xds_bootstrap_grpc.cc @@ -259,6 +259,13 @@ const JsonLoaderInterface* GrpcXdsBootstrap::JsonLoader(const JsonArgs&) { void GrpcXdsBootstrap::JsonPostLoad(const Json& /*json*/, const JsonArgs& /*args*/, ValidationErrors* errors) { + // Verify that there is at least one server present. + { + ValidationErrors::ScopedField field(errors, ".xds_servers"); + if (servers_.empty() && !errors->FieldHasErrors()) { + errors->AddError("must be non-empty"); + } + } // Verify that each authority has the right prefix in the // client_listener_resource_name_template field. { diff --git a/test/core/xds/xds_bootstrap_test.cc b/test/core/xds/xds_bootstrap_test.cc index bdb7707427e..86c0098fa64 100644 --- a/test/core/xds/xds_bootstrap_test.cc +++ b/test/core/xds/xds_bootstrap_test.cc @@ -314,6 +314,19 @@ TEST(XdsBootstrapTest, MissingXdsServers) { << bootstrap.status(); } +TEST(XdsBootstrapTest, EmptyXdsServers) { + const char* json_str = + "{" + " \"xds_servers\": [" + " ]" + "}"; + auto bootstrap = GrpcXdsBootstrap::Create(json_str); + EXPECT_EQ( + bootstrap.status().message(), + "errors validating JSON: [field:xds_servers error:must be non-empty]") + << bootstrap.status(); +} + TEST(XdsBootstrapTest, TopFieldsWrongTypes) { const char* json_str = "{" diff --git a/test/core/xds/xds_client_corpora/bootstrap_xds_servers_empty b/test/core/xds/xds_client_corpora/bootstrap_xds_servers_empty new file mode 100644 index 00000000000..04308e93c1f --- /dev/null +++ b/test/core/xds/xds_client_corpora/bootstrap_xds_servers_empty @@ -0,0 +1,10 @@ +bootstrap: "{\"xds_servers\": []}" +actions { + start_watch { + resource_type { + listener { + } + } + resource_name: "\003" + } +}