Commit bfa8a9aa authored by Kenton Varda's avatar Kenton Varda

Fix bug where DNS lookup would fail for very long hostnames.

parent a21a2975
......@@ -732,8 +732,8 @@ public:
addrTarget = &result.addr.inet4.sin_addr;
}
if (addrPart.size() < INET6_ADDRSTRLEN - 1) {
// addrPart is not necessarily NUL-terminated so we have to make a copy. :(
KJ_REQUIRE(addrPart.size() < INET6_ADDRSTRLEN - 1, "IP address too long.", addrPart);
char buffer[INET6_ADDRSTRLEN];
memcpy(buffer, addrPart.begin(), addrPart.size());
buffer[addrPart.size()] = '\0';
......@@ -753,12 +753,15 @@ public:
}
case 0:
// It's apparently not a simple address... fall back to DNS.
return lookupHost(lowLevel, kj::heapString(addrPart), nullptr, port, filter);
break;
default:
KJ_FAIL_SYSCALL("inet_pton", errno, af, addrPart);
}
}
return lookupHost(lowLevel, kj::heapString(addrPart), nullptr, port, filter);
}
static SocketAddress getLocalAddress(int sockfd) {
SocketAddress result;
result.addrlen = sizeof(addr);
......
......@@ -634,9 +634,9 @@ public:
addrTarget = &result.addr.inet4.sin_addr;
}
// addrPart is not necessarily NUL-terminated so we have to make a copy. :(
char buffer[64];
KJ_REQUIRE(addrPart.size() < sizeof(buffer) - 1, "IP address too long.", addrPart);
if (addrPart.size() < sizeof(buffer) - 1) {
// addrPart is not necessarily NUL-terminated so we have to make a copy. :(
memcpy(buffer, addrPart.begin(), addrPart.size());
buffer[addrPart.size()] = '\0';
......@@ -655,12 +655,15 @@ public:
}
case 0:
// It's apparently not a simple address... fall back to DNS.
return lookupHost(lowLevel, kj::heapString(addrPart), nullptr, port, filter);
break;
default:
KJ_FAIL_WIN32("InetPton", WSAGetLastError(), af, addrPart);
}
}
return lookupHost(lowLevel, kj::heapString(addrPart), nullptr, port, filter);
}
static SocketAddress getLocalAddress(SOCKET sockfd) {
SocketAddress result;
result.addrlen = sizeof(addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment