From 7ccff47151390a79f6126af9c8733d641bc87311 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:39:58 +0100 Subject: [PATCH] Protect asio exception hotfix (#4527) (#4530) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refs #20599: Handle error code before function call Signed-off-by: cferreiragonz * Apply suggestion Co-authored-by: Miguel Company --------- Signed-off-by: cferreiragonz Co-authored-by: Miguel Company (cherry picked from commit 08193d5f7eb4dcf3de8ecee3725f57bee28d35cd) Co-authored-by: Carlos Ferreira González --- src/cpp/rtps/transport/TCPTransportInterface.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cpp/rtps/transport/TCPTransportInterface.cpp b/src/cpp/rtps/transport/TCPTransportInterface.cpp index 9e686fcd44b..e984fc55cb2 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -262,11 +262,15 @@ Locator TCPTransportInterface::remote_endpoint_to_locator( { Locator locator; asio::error_code ec; - endpoint_to_locator(channel->remote_endpoint(ec), locator); + auto endpoint = channel->remote_endpoint(ec); if (ec) { LOCATOR_INVALID(locator); } + else + { + endpoint_to_locator(endpoint, locator); + } return locator; } @@ -275,11 +279,15 @@ Locator TCPTransportInterface::local_endpoint_to_locator( { Locator locator; asio::error_code ec; - endpoint_to_locator(channel->local_endpoint(ec), locator); + auto endpoint = channel->local_endpoint(ec); if (ec) { LOCATOR_INVALID(locator); } + else + { + endpoint_to_locator(endpoint, locator); + } return locator; }