From ebfabbe64fd8e471a1b0a86b6d2d2a6c38500ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ferreira=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 09:39:54 +0100 Subject: [PATCH] Protect asio exception hotfix (#4527) * 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) --- 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 f9cd60425e3..674c657bc7d 100644 --- a/src/cpp/rtps/transport/TCPTransportInterface.cpp +++ b/src/cpp/rtps/transport/TCPTransportInterface.cpp @@ -266,11 +266,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; } @@ -279,11 +283,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; }