linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04461
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2604: fix crash on unknown hosts
------------------------------------------------------------
revno: 2604
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2011-08-27 19:42:11 +0200
message:
fix crash on unknown hosts
modified:
dcpp/Socket.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/Socket.cpp'
--- dcpp/Socket.cpp 2011-08-26 20:17:04 +0000
+++ dcpp/Socket.cpp 2011-08-27 17:42:11 +0000
@@ -58,7 +58,7 @@
auto error = getLastError();
if(blockOk && error == WSAEWOULDBLOCK) {
- return -1;
+ return static_cast<decltype(ret)>(-1);
}
if(error != EINTR) {
@@ -761,12 +761,14 @@
addrinfo *result = 0;
- std::string ret;
- if(getaddrinfo(aDns.c_str(), NULL, &hints, &result) == 0) {
- ret = resolveName(result->ai_addr, result->ai_addrlen);
- ::freeaddrinfo(result);
+ auto err = ::getaddrinfo(aDns.c_str(), NULL, &hints, &result);
+ if(err) {
+ throw SocketException(err);
}
+ auto ret = resolveName(result->ai_addr, result->ai_addrlen);
+ ::freeaddrinfo(result);
+
return ret;
}
@@ -776,9 +778,13 @@
hints.ai_flags = flags;
hints.ai_socktype = type == TYPE_TCP ? SOCK_STREAM : SOCK_DGRAM;
hints.ai_protocol = type;
+
addrinfo *result = 0;
- check([&] { return ::getaddrinfo(name.empty() ? NULL : name.c_str(), port.empty() ? NULL : port.c_str(), &hints, &result); });
+ auto err = ::getaddrinfo(name.empty() ? NULL : name.c_str(), port.empty() ? NULL : port.c_str(), &hints, &result);
+ if(err) {
+ throw SocketException(err);
+ }
dcdebug("Resolved %s:%s to %s, next is %p\n", name.c_str(), port.c_str(),
resolveName(result->ai_addr, result->ai_addrlen).c_str(), result->ai_next);
@@ -788,7 +794,12 @@
string Socket::resolveName(const sockaddr* sa, socklen_t sa_len, int flags) {
char buf[1024];
- check([&] { return ::getnameinfo(sa, sa_len, buf, sizeof(buf), NULL, 0, flags); });
+
+ auto err = ::getnameinfo(sa, sa_len, buf, sizeof(buf), NULL, 0, flags);
+ if(err) {
+ throw SocketException(err);
+ }
+
return string(buf);
}