Commit c12c046e authored by Kenny Root's avatar Kenny Root
Browse files

Update d2i_SSL_SESSION test expectations

Update d2i_SSL_SESSION to only throw IOException and change tests to
expect that to happen. Since IOException is declared as a thrown
exception, non-test code should already be expecting this.

Bug: 27526112
Change-Id: Ic8c1a47debce9cb76221150d050be86d010c6ec3
parent 28c8e237
......@@ -504,6 +504,14 @@ static int throwNoSuchAlgorithmException(JNIEnv* env, const char* message) {
return jniThrowException(env, "java/security/NoSuchAlgorithmException", message);
}
/**
* Throws an IOException with the given string as a message.
*/
static int throwIOException(JNIEnv* env, const char* message) {
JNI_TRACE("throwIOException %s", message);
return jniThrowException(env, "java/io/IOException", message);
}
#if defined(OPENSSL_IS_BORINGSSL)
/**
* Throws a ParsingException with the given string as a message.
......@@ -5385,7 +5393,7 @@ static int NativeCrypto_BIO_read(JNIEnv* env, jclass, jlong bioRef, jbyteArray o
int read = BIO_read(bio, buffer.get(), outputSize);
if (read <= 0) {
jniThrowException(env, "java/io/IOException", "BIO_read");
throwIOException(env, "BIO_read");
JNI_TRACE("BIO_read(%p, %p) => threw IO exception", bio, outputJavaBytes);
return 0;
}
......@@ -5421,7 +5429,7 @@ static void NativeCrypto_BIO_write(JNIEnv* env, jclass, jlong bioRef, jbyteArray
env->GetByteArrayRegion(inputJavaBytes, offset, length, reinterpret_cast<jbyte*>(buffer.get()));
if (BIO_write(bio, buffer.get(), length) != length) {
freeOpenSslErrorState();
jniThrowException(env, "java/io/IOException", "BIO_write");
throwIOException(env, "BIO_write");
JNI_TRACE("BIO_write(%p, %p, %d, %d) => IO error", bio, inputJavaBytes, offset, length);
return;
}
......@@ -10672,8 +10680,8 @@ static jlong NativeCrypto_d2i_SSL_SESSION(JNIEnv* env, jclass, jbyteArray javaBy
if (ssl_session == nullptr ||
ucp != (reinterpret_cast<const unsigned char*>(bytes.get()) + bytes.size())) {
if (!throwExceptionIfNecessary(env, "d2i_SSL_SESSION")) {
jniThrowException(env, "java/io/IOException", "d2i_SSL_SESSION");
if (!throwExceptionIfNecessary(env, "d2i_SSL_SESSION", throwIOException)) {
throwIOException(env, "d2i_SSL_SESSION");
}
JNI_TRACE("NativeCrypto_d2i_SSL_SESSION => failure to convert");
return 0L;
......
......@@ -2621,8 +2621,17 @@ public class NativeCryptoTest extends TestCase {
} catch (NullPointerException expected) {
}
assertEquals(NULL, NativeCrypto.d2i_SSL_SESSION(new byte[0]));
assertEquals(NULL, NativeCrypto.d2i_SSL_SESSION(new byte[1]));
try {
NativeCrypto.d2i_SSL_SESSION(new byte[0]);
fail("Should throw IOException with invalid SSL_SESSION data");
} catch (IOException expected) {
}
try {
NativeCrypto.d2i_SSL_SESSION(new byte[1]);
fail("Should throw IOException with invalid SSL_SESSION data");
} catch (IOException expected) {
}
// positive testing by test_i2d_SSL_SESSION
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment