Skip to content

Commit

Permalink
[EE client channel resolver] Use std::strlen instead of sizeof in TXT…
Browse files Browse the repository at this point in the history
… record parsing (#33131)

This is a mistake made in #33030.
`sizeof()` would count the null byte terminated the C string and would
cause us to skip a byte if it is used as the index to
`result->substr()`. This would also crash if `result` only contains
`grpc_config=` as @drfloob pointed out.

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
  • Loading branch information
yijiem authored and wanlin31 committed May 18, 2023
1 parent 5040a92 commit 75f46eb
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,16 @@ void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper::
errors_.AddError(service_config.status().message());
service_config_json_ = service_config.status();
} else {
constexpr char kServiceConfigAttributePrefix[] = "grpc_config=";
static constexpr absl::string_view kServiceConfigAttributePrefix =
"grpc_config=";
auto result = std::find_if(service_config->begin(), service_config->end(),
[&](absl::string_view s) {
return absl::StartsWith(
s, kServiceConfigAttributePrefix);
});
if (result != service_config->end()) {
service_config_json_ =
result->substr(sizeof(kServiceConfigAttributePrefix));
result->substr(kServiceConfigAttributePrefix.size());
} else {
service_config_json_ = absl::UnavailableError(absl::StrCat(
"failed to find attribute prefix: ", kServiceConfigAttributePrefix,
Expand Down

0 comments on commit 75f46eb

Please sign in to comment.