aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Vartanian <flooey@google.com>2018-02-28 14:40:59 +0000
committerAdam Vartanian <flooey@google.com>2018-02-28 14:41:10 +0000
commit7e5fb7c809ec5f7130e94a54f7c08b9bfa035de4 (patch)
treebe78f5dd29a383da99fbe419bc6b9b919df09816
parentf753e05a9ea99c2f8aaf7e12cec1a00cbb5ee991 (diff)
parentae4ccbfe5f19aafb54ea14b1fb78043159a8bc93 (diff)
downloadconscrypt-7e5fb7c809ec5f7130e94a54f7c08b9bfa035de4.tar.gz
Merge upstream master
Reverts the change in SSLSocket exception behavior. Bug: 73922763 Test: cts -m CtsLibcoreTestCases -t com.android.org.conscrypt.javax.net.ssl Change-Id: Id8dfa1c81335cd6c707d8432073fbd40e8edf6c6
-rw-r--r--common/src/jni/main/cpp/conscrypt/native_crypto.cc8
-rw-r--r--openjdk-integ-tests/src/test/java/org/conscrypt/javax/net/ssl/SSLSocketTest.java12
2 files changed, 13 insertions, 7 deletions
diff --git a/common/src/jni/main/cpp/conscrypt/native_crypto.cc b/common/src/jni/main/cpp/conscrypt/native_crypto.cc
index d2955403..053315e1 100644
--- a/common/src/jni/main/cpp/conscrypt/native_crypto.cc
+++ b/common/src/jni/main/cpp/conscrypt/native_crypto.cc
@@ -7886,12 +7886,10 @@ static int sslRead(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, char* b
// A problem occurred during a system call, but this is not
// necessarily an error.
case SSL_ERROR_SYSCALL: {
- // Connection closed without proper shutdown. Throw a SocketException to
- // indicate that the socket is closed.
+ // Connection closed without proper shutdown. Tell caller we
+ // have reached end-of-stream.
if (result == 0) {
- conscrypt::jniutil::throwException(env, "java/net/SocketException",
- "Socket closed");
- return THROWN_EXCEPTION;
+ return -1;
}
// System call has been interrupted. Simply retry.
diff --git a/openjdk-integ-tests/src/test/java/org/conscrypt/javax/net/ssl/SSLSocketTest.java b/openjdk-integ-tests/src/test/java/org/conscrypt/javax/net/ssl/SSLSocketTest.java
index f224a0a6..930f4aef 100644
--- a/openjdk-integ-tests/src/test/java/org/conscrypt/javax/net/ssl/SSLSocketTest.java
+++ b/openjdk-integ-tests/src/test/java/org/conscrypt/javax/net/ssl/SSLSocketTest.java
@@ -1955,8 +1955,16 @@ public class SSLSocketTest {
// Read from the socket.
try {
toRead.setSoTimeout(readingTimeoutMillis);
- toRead.getInputStream().read();
- fail();
+ int read = toRead.getInputStream().read();
+ // In the case of reading the wrapper and closing the underlying socket,
+ // there is a race condition between the reading thread being woken and
+ // reading the socket again and the closing thread marking the file descriptor
+ // as invalid. If the latter happens first, a SocketException is thrown,
+ // but if the former happens first it just looks like the peer closed the
+ // connection and a -1 return is acceptable.
+ if (read != -1 || readUnderlying || !closeUnderlying) {
+ fail();
+ }
} catch (SocketTimeoutException e) {
throw e;
} catch (IOException expected) {