diff options
-rw-r--r-- | src/share/native/sun/security/ec/ECC_JNI.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/share/native/sun/security/ec/ECC_JNI.cpp b/src/share/native/sun/security/ec/ECC_JNI.cpp index f2612adc2..684f82eac 100644 --- a/src/share/native/sun/security/ec/ECC_JNI.cpp +++ b/src/share/native/sun/security/ec/ECC_JNI.cpp @@ -41,7 +41,9 @@ extern "C" { void ThrowException(JNIEnv *env, const char *exceptionName) { jclass exceptionClazz = env->FindClass(exceptionName); - env->ThrowNew(exceptionClazz, NULL); + if (exceptionClazz != NULL) { + env->ThrowNew(exceptionClazz, NULL); + } } /* @@ -80,7 +82,6 @@ jbyteArray getEncodedBytes(JNIEnv *env, SECItem *hSECItem) return jEncodedBytes; } - /* * Class: sun_security_ec_ECKeyPairGenerator * Method: generateECKeyPair @@ -103,6 +104,9 @@ JNICALL Java_sun_security_ec_ECKeyPairGenerator_generateECKeyPair params_item.len = env->GetArrayLength(encodedParams); params_item.data = (unsigned char *) env->GetByteArrayElements(encodedParams, 0); + if (params_item.data == NULL) { + goto cleanup; + } // Fill a new ECParams using the supplied OID if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { @@ -170,6 +174,7 @@ cleanup: SECITEM_FreeItem(&privKey->publicValue, B_FALSE); free(privKey); } + if (pSeedBuffer) { delete [] pSeedBuffer; } @@ -213,6 +218,9 @@ JNICALL Java_sun_security_ec_ECDSASignature_signDigest params_item.len = env->GetArrayLength(encodedParams); params_item.data = (unsigned char *) env->GetByteArrayElements(encodedParams, 0); + if (params_item.data == NULL) { + goto cleanup; + } // Fill a new ECParams using the supplied OID if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { @@ -226,6 +234,9 @@ JNICALL Java_sun_security_ec_ECDSASignature_signDigest privKey.privateValue.len = env->GetArrayLength(privateKey); privKey.privateValue.data = (unsigned char *) env->GetByteArrayElements(privateKey, 0); + if (privKey.privateValue.data == NULL) { + goto cleanup; + } // Prepare a buffer for the signature (twice the key length) pSignedDigestBuffer = new jbyte[ecparams->order.len * 2]; @@ -245,6 +256,9 @@ JNICALL Java_sun_security_ec_ECDSASignature_signDigest // Create new byte array temp = env->NewByteArray(signature_item.len); + if (temp == NULL) { + goto cleanup; + } // Copy data from native buffer env->SetByteArrayRegion(temp, 0, signature_item.len, pSignedDigestBuffer); @@ -317,6 +331,9 @@ JNICALL Java_sun_security_ec_ECDSASignature_verifySignedDigest params_item.len = env->GetArrayLength(encodedParams); params_item.data = (unsigned char *) env->GetByteArrayElements(encodedParams, 0); + if (params_item.data == NULL) { + goto cleanup; + } // Fill a new ECParams using the supplied OID if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { @@ -369,25 +386,34 @@ JNICALL Java_sun_security_ec_ECDHKeyAgreement_deriveKey (JNIEnv *env, jclass clazz, jbyteArray privateKey, jbyteArray publicKey, jbyteArray encodedParams) { jbyteArray jSecret = NULL; + ECParams *ecparams = NULL; // Extract private key value SECItem privateValue_item; privateValue_item.len = env->GetArrayLength(privateKey); privateValue_item.data = (unsigned char *) env->GetByteArrayElements(privateKey, 0); + if (privateValue_item.data == NULL) { + goto cleanup; + } // Extract public key value SECItem publicValue_item; publicValue_item.len = env->GetArrayLength(publicKey); publicValue_item.data = (unsigned char *) env->GetByteArrayElements(publicKey, 0); + if (publicValue_item.data == NULL) { + goto cleanup; + } // Initialize the ECParams struct - ECParams *ecparams = NULL; SECKEYECParams params_item; params_item.len = env->GetArrayLength(encodedParams); params_item.data = (unsigned char *) env->GetByteArrayElements(encodedParams, 0); + if (params_item.data == NULL) { + goto cleanup; + } // Fill a new ECParams using the supplied OID if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { @@ -409,6 +435,9 @@ JNICALL Java_sun_security_ec_ECDHKeyAgreement_deriveKey // Create new byte array jSecret = env->NewByteArray(secret_item.len); + if (jSecret == NULL) { + goto cleanup; + } // Copy bytes from the SECItem buffer to a Java byte array env->SetByteArrayRegion(jSecret, 0, secret_item.len, |