RFR 8067105: Socket returned by ServerSocket.accept() is inherited by child process on Windows

Chris Hegarty chris.hegarty at oracle.com
Wed Dec 17 15:47:17 UTC 2014

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, 

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);


More information about the net-dev mailing list