1
0
mirror of https://github.com/anope/anope.git synced 2026-06-29 12:16:38 +02:00

Don't attempt to connect to the uplink if given invalid hostnames

This commit is contained in:
Adam
2011-04-25 04:17:21 -04:00
parent 03d2378a9f
commit 4a733c93d4
5 changed files with 46 additions and 18 deletions
+14 -4
View File
@@ -129,17 +129,27 @@ void sockaddrs::pton(int type, const Anope::string &address, int pport)
switch (type)
{
case AF_INET:
if (inet_pton(type, address.c_str(), &sa4.sin_addr) < 1)
throw SocketException(Anope::string("Invalid host: ") + Anope::LastError());
{
int i = inet_pton(type, address.c_str(), &sa4.sin_addr);
if (i == 0)
throw SocketException("Invalid host");
else if (i <= -1)
throw SocketException("Invalid host: " + Anope::LastError());
sa4.sin_family = type;
sa4.sin_port = htons(pport);
return;
}
case AF_INET6:
if (inet_pton(type, address.c_str(), &sa6.sin6_addr) < 1)
throw SocketException(Anope::string("Invalid host: ") + Anope::LastError());
{
int i = inet_pton(type, address.c_str(), &sa6.sin6_addr);
if (i == 0)
throw SocketException("Invalid host");
else if (i <= -1)
throw SocketException("Invalid host: " + Anope::LastError());
sa6.sin6_family = type;
sa6.sin6_port = htons(pport);
return;
}
default:
break;
}