[c-ares] Fix inverted length check in GrpcPolledFdWindows (#38101)

Fix https://github.com/grpc/grpc/issues/37969.

There is an inverted length check in GrpcPolledFdWindows before memcpying from gRPC's `recv_from_source_addr_` into c-ares' socket address structure. In newer c-ares version, it changed to use `struct sockaddr_storage` for the socket address which is 128 bytes and hit this issue.

<!--

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.

-->

Closes #38101

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/38101 from yijiem:37969 282fc8269e
PiperOrigin-RevId: 696607100
test_696559679
Yijie Ma 1 week ago committed by Copybara-Service
parent 94cbb67608
commit e352e896cb
  1. 2
      src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc
  2. 2
      src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc

@ -224,7 +224,7 @@ class GrpcPolledFdWindows : public GrpcPolledFd {
// c-ares overloads this recv_from virtual socket function to receive
// data on both UDP and TCP sockets, and from is nullptr for TCP.
if (from != nullptr) {
CHECK(*from_len <= recv_from_source_addr_len_);
CHECK(*from_len >= recv_from_source_addr_len_);
memcpy(from, &recv_from_source_addr_, recv_from_source_addr_len_);
*from_len = recv_from_source_addr_len_;
}

@ -307,7 +307,7 @@ class GrpcPolledFdWindows final : public GrpcPolledFd {
// c-ares overloads this recv_from virtual socket function to receive
// data on both UDP and TCP sockets, and from is nullptr for TCP.
if (from != nullptr) {
CHECK(*from_len <= recv_from_source_addr_len_);
CHECK(*from_len >= recv_from_source_addr_len_);
memcpy(from, &recv_from_source_addr_, recv_from_source_addr_len_);
*from_len = recv_from_source_addr_len_;
}

Loading…
Cancel
Save