diff options
author | Adam <Adam@anope.org> | 2011-04-25 04:17:21 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-04-25 04:17:21 -0400 |
commit | 4a733c93d45e0ca5d757abf826d65bc1cbaf610e (patch) | |
tree | e09f093a9926b4285ea1d33da93828ddd5b6bbcb /src/sockets.cpp | |
parent | 03d2378a9fc2fdc868ee4476597ec1901242a0c5 (diff) |
Don't attempt to connect to the uplink if given invalid hostnames
Diffstat (limited to 'src/sockets.cpp')
-rw-r--r-- | src/sockets.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
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; } |