summaryrefslogtreecommitdiff
path: root/annotations/generate_annotated_java_files.py
diff options
context:
space:
mode:
authorTobias Thierer <tobiast@google.com>2017-08-15 18:25:43 +0100
committerTobias Thierer <tobiast@google.com>2017-08-16 15:49:03 +0100
commitc725b7f127b9a695fa310cd0e6ac61e4d28ef3b5 (patch)
tree5d421f239abe5dbf56ddcf878152b254a602639c /annotations/generate_annotated_java_files.py
parent1ed1d7a78f4b5616526a4529d1473d9f37a0cf8c (diff)
Deal with preclosed fd in IoBridge.getLocalInetSocketAddress().
Five out of six callers, in particular ConnectDetail (which is used to construct an exception message), pass in an fd value representing an AbstractPlainSocketImpl on which another thread may concurrently call close(). While PlainSocketImpl delays final closing of the socket until all threads have completed their ongoing calls, PlainSocketImpl.socketClose0(true) will still preclose the socket, during which the fd will be dup2'ed to an AF_UNIX socket. For such preclosed sockets, getsockname() will return the UnixSocketAddress of the marker FileDescriptor, leading to a ClassCastException in IoBridge.getLocalInetSocketAddress(), which causes crash bugs in applications. To fix the common use case without needing to touch the preclose logic, this CL changes IoBridge.getLocalInetSocketAddress() to throw a SocketException rather than a ClassCastException in the case where (socketAddress != null) && !(socketAddress instanceof InetSocketAddress). The case of socketAddress == null should not normally occur, but also wouldn't have resulted in a ClassCastException so was not touched by this CL, in order to minimize behavior changes. Note on why SocketException is the correct behavior for all current callers that previously might have encountered ClassCastException: - In connectDetail(), the SocketException is caught and leads to no inetAddress being included in the exception message constructed for its caller. This is correct behavior. - Inet6AddressImpl.icmpEcho() uses a fd that is confined to the current thread, and therefore not at risk of concurrent preclose. - All other callers are in the middle of accept(), bind(), or connect(). For these, SocketException is the correct response when the socket has been preclosed. Test: LibcoreTestCases Bug: 64209834 (cherry picked from commit 6d580b699f58a3d7c7cf27eafda042b58b674dc0) Change-Id: Ie21ad68d6b63d58317284ea71f06b216f6e80c2a
Diffstat (limited to 'annotations/generate_annotated_java_files.py')
0 files changed, 0 insertions, 0 deletions