RFR 8067105: Socket returned by ServerSocket.accept() is inherited by child process on Windows
dmitry.samersoff at oracle.com
Thu Dec 18 12:22:28 UTC 2014
In a windows world it's rather common to rely on socket inheritance
e.g. set socket to stdin(stdout) of child process and do CreateProcess.
So please make sure your changes don't have side effects, also it might
be better to control handler inheritance in one place only (at
CreateProcess call) and don't manage it explicitly in other places.
On 2014-12-17 18:47, Chris Hegarty wrote:
> A socket connection which is returned by ServerSocket.accept() is
> inherited by a child process. The expected behavior is that the socket
> connection is not inherited by the child process. This is an oversight
> in the original implementation, that only sets HANDLE_FLAG_INHERIT for
> newly created sockets.
> The native socket returned by ServerSocket.accept() should be configured
> so it will not be inherited by a child process,
> SetHandleInformation(<HANDLE>, HANDLE_FLAG_INHERIT, FALSE) .
> The change is in Java_java_net_DualStackPlainSocketImpl_accept0
> diff --git
> --- a/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c
> +++ b/src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c
> @@ -294,6 +294,8 @@
> return -1;
> + SetHandleInformation((HANDLE)(UINT_PTR)newfd, HANDLE_FLAG_INHERIT,
> ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
> isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
> (*env)->SetObjectArrayElement(env, isaa, 0, isa);
Oracle Java development team, Saint Petersburg, Russia
* I would love to change the world, but they won't give me the sources.
More information about the net-dev