[AndroidCrypto] Add exception check to RsaVerificationPrimitive (#49443)
authorElinor Fung <elfung@microsoft.com>
Thu, 11 Mar 2021 02:11:17 +0000 (18:11 -0800)
committerGitHub <noreply@github.com>
Thu, 11 Mar 2021 02:11:17 +0000 (02:11 +0000)
* Add exception check to AndroidCryptoNative_RsaVerificationPrimitive

* Fix return error code

src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_rsa.c

index b96db20..68091b7 100644 (file)
@@ -220,6 +220,15 @@ PALEXPORT int32_t AndroidCryptoNative_RsaVerificationPrimitive(int32_t flen, uin
     jbyteArray fromBytes = (*env)->NewByteArray(env, flen);
     (*env)->SetByteArrayRegion(env, fromBytes, 0, flen, (jbyte*)from);
     jbyteArray decryptedBytes = (jbyteArray)(*env)->CallObjectMethod(env, cipher, g_cipherDoFinal2Method, fromBytes);
+    if (CheckJNIExceptions(env))
+    {
+        (*env)->DeleteLocalRef(env, cipher);
+        (*env)->DeleteLocalRef(env, fromBytes);
+        (*env)->DeleteLocalRef(env, decryptedBytes);
+        (*env)->DeleteLocalRef(env, algName);
+        return FAIL;
+    }
+
     jsize decryptedBytesLen = (*env)->GetArrayLength(env, decryptedBytes);
     (*env)->GetByteArrayRegion(env, decryptedBytes, 0, decryptedBytesLen, (jbyte*) to);