Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACE_INET_Addr::set errantly succeeds when ACE_LACKS_GETSERVBYNAME #2080

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ACE/ace/INET_Addr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions ACE/tests/INET_Addr_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,43 @@ static bool test_multiple ()
return success;
}

static bool test_port_names()
{
bool success = true;

ACE_INET_Addr addr;

#if defined (ACE_LACKS_GETSERVBYNAME)
// Since we don't have getservbyname, the call to set should fail.
// Check that the call does in fact fail.
if (addr.set("telnet") == 0)
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("set with 'telnet' succeeded (expected failure)\n")));
success = false;
}
#else
if (addr.set("telnet") != 0)
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("set with 'telnet' failed (expected success)\n")));
success = false;
}

if (addr != ACE_INET_Addr("0.0.0.0:23"))
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("set with 'telnet' failed to yield correct address\n")));
success = false;
}
#endif /* ACE_LACKS_GETSERVBYNAME */

if (addr.set("not a port name") == 0)
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("set with 'not a port name' succeeded (expected failure)\n")));
success = false;
}

return success;
}

struct Address {
const char* name;
bool loopback;
Expand Down Expand Up @@ -561,6 +598,9 @@ int run_main (int, ACE_TCHAR *[])
status = 1;
}

if (!test_port_names ())
status = 1;

ACE_END_TEST;

return status;
Expand Down