From 8114e1ee8badf12f4211f15c85724d964822e029 Mon Sep 17 00:00:00 2001 From: valeriep Date: Wed, 22 Jul 2009 17:52:21 -0700 Subject: [PATCH] 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test Summary: Initialize relevant return value to NULL Reviewed-by: vinnie --- .../sun/security/pkcs11/wrapper/p11_general.c | 4 ++-- .../sun/security/pkcs11/wrapper/p11_keymgmt.c | 12 ++++-------- .../sun/security/pkcs11/wrapper/p11_objmgmt.c | 14 +++++--------- .../native/sun/security/pkcs11/wrapper/p11_sign.c | 2 +- .../native/sun/security/pkcs11/wrapper/p11_util.c | 10 ++++------ .../sun/security/pkcs11/wrapper/pkcs11wrapper.h | 2 +- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c index e6cbe2b6d..8e80a5907 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c @@ -337,7 +337,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSlotList CK_ULONG ckTokenNumber; CK_SLOT_ID_PTR ckpSlotList; CK_BBOOL ckTokenPresent; - jlongArray jSlotList; + jlongArray jSlotList = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -637,7 +637,7 @@ Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetMechanismList CK_SLOT_ID ckSlotID; CK_ULONG ckMechanismNumber; CK_MECHANISM_TYPE_PTR ckpMechanismList; - jlongArray jMechanismList; + jlongArray jMechanismList = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c index aab0491a3..501ead98c 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c @@ -73,9 +73,8 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKey CK_MECHANISM ckMechanism; CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; - CK_OBJECT_HANDLE ckKeyHandle; + CK_OBJECT_HANDLE ckKeyHandle = 0; jlong jKeyHandle = 0L; - CK_ULONG i; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -151,8 +150,7 @@ JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Generate CK_OBJECT_HANDLE_PTR ckpPublicKeyHandle; /* pointer to Public Key */ CK_OBJECT_HANDLE_PTR ckpPrivateKeyHandle; /* pointer to Private Key */ CK_OBJECT_HANDLE_PTR ckpKeyHandles; /* pointer to array with Public and Private Key */ - jlongArray jKeyHandles; - CK_ULONG i; + jlongArray jKeyHandles = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -299,9 +297,8 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1UnwrapKey CK_ULONG ckWrappedKeyLength; CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; - CK_OBJECT_HANDLE ckKeyHandle; + CK_OBJECT_HANDLE ckKeyHandle = 0; jlong jKeyHandle = 0L; - CK_ULONG i; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -478,8 +475,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; CK_OBJECT_HANDLE ckKeyHandle = 0; - jlong jKeyHandle; - CK_ULONG i; + jlong jKeyHandle = 0L; CK_RV rv; CK_OBJECT_HANDLE_PTR phKey = &ckKeyHandle; diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c b/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c index a72f20d27..307f2ee73 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c @@ -72,8 +72,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CreateObject CK_OBJECT_HANDLE ckObjectHandle; CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; - jlong jObjectHandle; - CK_ULONG i; + jlong jObjectHandle = 0L; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -114,8 +113,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CopyObject CK_OBJECT_HANDLE ckNewObjectHandle; CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; - jlong jNewObjectHandle; - CK_ULONG i; + jlong jNewObjectHandle = 0L; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -180,7 +178,7 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetObjectSize CK_SESSION_HANDLE ckSessionHandle; CK_OBJECT_HANDLE ckObjectHandle; CK_ULONG ckObjectSize; - jlong jObjectSize; + jlong jObjectSize = 0L; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -217,7 +215,7 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetAttributeVa CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; CK_ULONG ckBufferLength; - CK_ULONG i, j; + CK_ULONG i; jobject jAttribute; CK_RV rv; @@ -307,7 +305,6 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetAttributeVa CK_OBJECT_HANDLE ckObjectHandle; CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; - CK_ULONG i; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -342,7 +339,6 @@ JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObjectsIni CK_SESSION_HANDLE ckSessionHandle; CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; CK_ULONG ckAttributesLength; - CK_ULONG i; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); @@ -385,7 +381,7 @@ JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObje CK_ULONG ckMaxObjectLength; CK_OBJECT_HANDLE_PTR ckpObjectHandleArray; CK_ULONG ckActualObjectCount; - jlongArray jObjectHandleArray; + jlongArray jObjectHandleArray = NULL; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); if (ckpFunctions == NULL) { return NULL; } diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c index e55755d1c..6c60fddd9 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c @@ -110,7 +110,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign CK_BYTE_PTR ckpSignature; CK_ULONG ckDataLength; CK_ULONG ckSignatureLength = 0; - jbyteArray jSignature; + jbyteArray jSignature = NULL; CK_RV rv; CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); diff --git a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c index d4c12a06b..98ec9c3b2 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c +++ b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c @@ -194,16 +194,14 @@ jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue) jclass jPKCS11ExceptionClass; jmethodID jConstructor; jthrowable jPKCS11Exception; - jlong jErrorCode; + jlong jErrorCode = 0L; - if (returnValue == CKR_OK) { - return 0L ; - } else { + if (returnValue != CKR_OK) { + jErrorCode = ckULongToJLong(returnValue); jPKCS11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION); if (jPKCS11ExceptionClass != NULL) { jConstructor = (*env)->GetMethodID(env, jPKCS11ExceptionClass, "", "(J)V"); if (jConstructor != NULL) { - jErrorCode = ckULongToJLong(returnValue); jPKCS11Exception = (jthrowable) (*env)->NewObject(env, jPKCS11ExceptionClass, jConstructor, jErrorCode); if (jPKCS11Exception != NULL) { (*env)->Throw(env, jPKCS11Exception); @@ -211,8 +209,8 @@ jlong ckAssertReturnValueOK(JNIEnv *env, CK_RV returnValue) } } (*env)->DeleteLocalRef(env, jPKCS11ExceptionClass); - return jErrorCode ; } + return jErrorCode ; } /* diff --git a/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h b/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h index 9dd90c304..78a73f15f 100644 --- a/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h +++ b/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h @@ -300,7 +300,7 @@ void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jAArray, CK_ATT /* funktions to convert a CK-type array and the array length to a Java array */ -jcharArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength); +jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_ULONG ckLength); jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK_ULONG ckLength); jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_ULONG length); jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArray, CK_ULONG ckLength); -- GitLab