From 4220e17bb615874d3dc8c1ceadfcae322feb409e Mon Sep 17 00:00:00 2001 From: Ashitha Santhosh Date: Mon, 17 Aug 2020 16:37:02 -0700 Subject: [PATCH 1/2] Fixed error. --- .../security/authorization/evaluate_args.cc | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/core/lib/security/authorization/evaluate_args.cc b/src/core/lib/security/authorization/evaluate_args.cc index c5ba7820080..2d88ab808a6 100644 --- a/src/core/lib/security/authorization/evaluate_args.cc +++ b/src/core/lib/security/authorization/evaluate_args.cc @@ -70,41 +70,28 @@ std::multimap EvaluateArgs::GetHeaders() } absl::string_view EvaluateArgs::GetSpiffeId() const { - absl::string_view spiffe_id; if (auth_context_ == nullptr) { - return spiffe_id; + return ""; } grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name( auth_context_, GRPC_PEER_SPIFFE_ID_PROPERTY_NAME); const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it); - if (prop == nullptr) return spiffe_id; - if (strncmp(prop->value, GRPC_PEER_SPIFFE_ID_PROPERTY_NAME, - prop->value_length) != 0) { - return spiffe_id; - } - if (grpc_auth_property_iterator_next(&it) != nullptr) return spiffe_id; - spiffe_id = absl::string_view( + if (prop == nullptr || grpc_auth_property_iterator_next(&it) != nullptr) + return ""; + return absl::string_view( reinterpret_cast(prop->value, prop->value_length)); - return spiffe_id; } absl::string_view EvaluateArgs::GetCertServerName() const { - absl::string_view name; if (auth_context_ == nullptr) { - return name; + return ""; } grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name( auth_context_, GRPC_X509_CN_PROPERTY_NAME); const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it); - if (prop == nullptr) return name; - if (strncmp(prop->value, GRPC_X509_CN_PROPERTY_NAME, prop->value_length) != - 0) { - return name; - } - if (grpc_auth_property_iterator_next(&it) != nullptr) return name; - name = absl::string_view( - reinterpret_cast(prop->value, prop->value_length)); - return name; + if (prop == nullptr || grpc_auth_property_iterator_next(&it) != nullptr) + return ""; + return absl::string_view(prop->value, prop->value_length); } } // namespace grpc_core From ae4a2472b9b158fd4b248e34dd89dc9eb66d965d Mon Sep 17 00:00:00 2001 From: Ashitha Santhosh Date: Mon, 17 Aug 2020 16:41:18 -0700 Subject: [PATCH 2/2] Remove cast. --- src/core/lib/security/authorization/evaluate_args.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/lib/security/authorization/evaluate_args.cc b/src/core/lib/security/authorization/evaluate_args.cc index 2d88ab808a6..dc6484550a4 100644 --- a/src/core/lib/security/authorization/evaluate_args.cc +++ b/src/core/lib/security/authorization/evaluate_args.cc @@ -76,10 +76,10 @@ absl::string_view EvaluateArgs::GetSpiffeId() const { grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name( auth_context_, GRPC_PEER_SPIFFE_ID_PROPERTY_NAME); const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it); - if (prop == nullptr || grpc_auth_property_iterator_next(&it) != nullptr) + if (prop == nullptr || grpc_auth_property_iterator_next(&it) != nullptr) { return ""; - return absl::string_view( - reinterpret_cast(prop->value, prop->value_length)); + } + return absl::string_view(prop->value, prop->value_length); } absl::string_view EvaluateArgs::GetCertServerName() const { @@ -89,8 +89,9 @@ absl::string_view EvaluateArgs::GetCertServerName() const { grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name( auth_context_, GRPC_X509_CN_PROPERTY_NAME); const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it); - if (prop == nullptr || grpc_auth_property_iterator_next(&it) != nullptr) + if (prop == nullptr || grpc_auth_property_iterator_next(&it) != nullptr) { return ""; + } return absl::string_view(prop->value, prop->value_length); }