mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
Improve buffer handling in Windows sk_getaddr() -- we were passing
uninitialised storage into WSAAddressToString()'s length function (and presumably getting away with it by luck). Also improve error handling (exposed by my Wine installation, which returns an error from WSAAddressToString() for connections to localhost for some reason). [originally from svn r8737]
This commit is contained in:
parent
138ec34844
commit
06497952de
@ -584,13 +584,19 @@ void sk_getaddr(SockAddr addr, char *buf, int buflen)
|
||||
|
||||
#ifndef NO_IPV6
|
||||
if (step.ai) {
|
||||
int err = 0;
|
||||
if (p_WSAAddressToStringA) {
|
||||
DWORD dwbuflen;
|
||||
p_WSAAddressToStringA(step.ai->ai_addr, step.ai->ai_addrlen,
|
||||
NULL, buf, &dwbuflen);
|
||||
buflen = dwbuflen;
|
||||
DWORD dwbuflen = buflen;
|
||||
err = p_WSAAddressToStringA(step.ai->ai_addr, step.ai->ai_addrlen,
|
||||
NULL, buf, &dwbuflen);
|
||||
} else
|
||||
strncpy(buf, "IPv6", buflen);
|
||||
err = -1;
|
||||
if (err) {
|
||||
strncpy(buf, addr->hostname, buflen);
|
||||
if (!buf[0])
|
||||
strncpy(buf, "<unknown>", buflen);
|
||||
buf[buflen-1] = '\0';
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (SOCKADDR_FAMILY(addr, step) == AF_INET) {
|
||||
|
Loading…
Reference in New Issue
Block a user