1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

Make Windows sockets non-inheritable

When we create a socket with socket() (in try_connect, sk_newlistener, and
ipv4_is_local_addr) also call SetHandleInformation to disable handle
inheritance for this socket.  This fixes dup-sessions-dont-close.
This commit is contained in:
Owen Dunn 2017-02-19 13:49:12 +00:00
parent efb4996d31
commit 4455604dbc

View File

@ -774,6 +774,8 @@ static int ipv4_is_local_addr(struct in_addr addr)
SOCKET s = p_socket(AF_INET, SOCK_DGRAM, 0);
DWORD retbytes;
SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0);
if (p_WSAIoctl &&
p_WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0,
local_interfaces, sizeof(local_interfaces),
@ -1022,6 +1024,8 @@ static DWORD try_connect(Actual_Socket sock)
goto ret;
}
SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0);
if (sock->oobinline) {
BOOL b = TRUE;
p_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (void *) &b, sizeof(b));
@ -1303,6 +1307,8 @@ Socket sk_newlistener(const char *srcaddr, int port, Plug plug,
return (Socket) ret;
}
SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0);
ret->oobinline = 0;
p_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));