From 56aaafb5426fde5fb0ddab635e04d8375baa7c39 Mon Sep 17 00:00:00 2001 From: "Justin R. Wilson" Date: Wed, 21 Jun 2023 11:28:26 -0500 Subject: [PATCH] `ACE_INET_Addr::set` errantly succeeds when ACE_LACKS_GETSERVBYNAME Problem ------- Calling `set("1.2.3.4")` on an ACE_INET_Addr eventually tries to part it as a port name. When `ACE_LACKS_GETSERVBYNAME`, this succeeds returning port number 0 with the reset address. When port names are not expected, this breaks a useful idiom of parsing addresses that may or may not contain port numbers: ACE_INET_Addr addr; if (addr.set(x) == 0) { // Success, address contained a port number } else if (addr.set(u_short(0), x) == 0) { // Success, address did not contain a port number. } else { // Fail } Solution -------- Return -1 for the port number when `ACE_LACKS_GETSERVBYNAME`. --- ACE/ace/INET_Addr.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ACE/ace/INET_Addr.cpp b/ACE/ace/INET_Addr.cpp index 58140d71ad428..25a1fb5d74fb7 100644 --- a/ACE/ace/INET_Addr.cpp +++ b/ACE/ace/INET_Addr.cpp @@ -468,12 +468,11 @@ static int get_port_number_from_name (const char port_name[], } // We try to resolve port number from its name. + port_number = -1; #if defined (ACE_LACKS_GETSERVBYNAME) - port_number = 0; ACE_UNUSED_ARG (port_name); ACE_UNUSED_ARG (protocol); #else - port_number = -1; servent sentry; ACE_SERVENT_DATA buf; servent *sp = ACE_OS::getservbyname_r (port_name,