changeset 1500:cd7758c85d13

6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test Summary: Initialize relevant return value to NULL Reviewed-by: vinnie
author valeriep
date Wed, 22 Jul 2009 17:52:21 -0700
parents 29b076bfeafd
children 4b287af811ba
files src/share/native/sun/security/pkcs11/wrapper/p11_general.c src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c src/share/native/sun/security/pkcs11/wrapper/p11_sign.c src/share/native/sun/security/pkcs11/wrapper/p11_util.c src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
diffstat 6 files changed, 17 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c	Wed Jul 22 16:41:14 2009 +0800
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c	Wed Jul 22 17:52:21 2009 -0700
@@ -337,7 +337,7 @@
     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 @@
     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);
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c	Wed Jul 22 16:41:14 2009 +0800
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c	Wed Jul 22 17:52:21 2009 -0700
@@ -73,9 +73,8 @@
     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 @@
     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 @@
     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 @@
     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;
 
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c	Wed Jul 22 16:41:14 2009 +0800
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_objmgmt.c	Wed Jul 22 17:52:21 2009 -0700
@@ -72,8 +72,7 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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; }
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c	Wed Jul 22 16:41:14 2009 +0800
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c	Wed Jul 22 17:52:21 2009 -0700
@@ -110,7 +110,7 @@
     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);
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c	Wed Jul 22 16:41:14 2009 +0800
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c	Wed Jul 22 17:52:21 2009 -0700
@@ -194,16 +194,14 @@
     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, "<init>", "(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 @@
             }
         }
         (*env)->DeleteLocalRef(env, jPKCS11ExceptionClass);
-        return jErrorCode ;
     }
+    return jErrorCode ;
 }
 
 /*
--- a/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h	Wed Jul 22 16:41:14 2009 +0800
+++ b/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h	Wed Jul 22 17:52:21 2009 -0700
@@ -300,7 +300,7 @@
 
 /* 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);