summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-04-25 04:17:21 -0400
committerAdam <Adam@anope.org>2011-04-25 04:17:21 -0400
commit4a733c93d45e0ca5d757abf826d65bc1cbaf610e (patch)
treee09f093a9926b4285ea1d33da93828ddd5b6bbcb /src
parent03d2378a9fc2fdc868ee4476597ec1901242a0c5 (diff)
Don't attempt to connect to the uplink if given invalid hostnames
Diffstat (limited to 'src')
-rw-r--r--src/dns.cpp6
-rw-r--r--src/main.cpp8
-rw-r--r--src/sockets.cpp18
3 files changed, 26 insertions, 6 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index e5a2c3098..45b3db6bd 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -221,6 +221,11 @@ inline DNSRecord::DNSRecord(const Anope::string &n) : name(n)
this->created = Anope::CurTime;
}
+DNSRecord::operator bool() const
+{
+ return !this->result.empty();
+}
+
DNSSocket::DNSSocket() : ConnectionSocket(false, SOCK_DGRAM)
{
}
@@ -613,7 +618,6 @@ DNSRecord DNSManager::BlockingQuery(const Anope::string &mask, QueryType qt)
DNSRecord result(mask);
addrinfo *addrresult, hints;
- result.result = mask;
result.type = qt;
int type = AF_UNSPEC;
diff --git a/src/main.cpp b/src/main.cpp
index 3ca033507..b71a7754a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -369,6 +369,12 @@ static bool Connect()
DNSRecord req = DNSManager::BlockingQuery(uplink_server->host, uplink_server->ipv6 ? DNS_QUERY_AAAA : DNS_QUERY_A);
+ if (!req)
+ {
+ Log() << "Unable to connect to server " << servernum << " (" << uplink_server->host << ":" << uplink_server->port << "): Invalid hostname/IP";
+ continue;
+ }
+
try
{
new UplinkSocket(uplink_server->ipv6);
@@ -376,7 +382,7 @@ static bool Connect()
}
catch (const SocketException &ex)
{
- Log() << "Unable to connect to server" << servernum << " (" << uplink_server->host << ":" << uplink_server->port << "), " << ex.GetReason();
+ Log() << "Unable to connect to server " << servernum << " (" << uplink_server->host << ":" << uplink_server->port << "): " << ex.GetReason();
continue;
}
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 941169c17..3f334e26e 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -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;
}