Avoid races between OpenSSLSocketImpl I/O and close()

The previous change:

    commit 5f2e6872311240319509aed64d9f58cd5b64719b
    Author: Brian Carlstrom <bdc@google.com>
    Date:   Mon Aug 23 14:06:51 2010 -0700

    SSLSocket.read should throw SocketException not NullPointerException

added checkOpen() to throw SocketException instead of
NullPointerException, but there was still a race between read/write on
one thread and close on another that could allow a
NullPointerException to escape. This change moves checkOpen() calls to
be protected by the existing writeLock/readLock/handshakeLock
synchronzied blocks to avoid this case.

byte buffer error checking for read/write is also moved into the to
lock region to preserve compatability as measured by the test:
    libcore.javax.net.ssl.SSLSocketTest#test_SSLSocket_close

Bug: 3153162
Change-Id: I16299f09dc91871407e88eb718073d21a816f683
1 file changed