From: Owen Dunn Date: Sun, 19 Feb 2017 13:49:12 +0000 (+0000) Subject: Make Windows sockets non-inheritable X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=4455604dbce2d175ce1d601d51472bb1b0a535d8;p=PuTTY.git 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. --- diff --git a/windows/winnet.c b/windows/winnet.c index fb121e3f..98753237 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -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));