changeset 13649:273fcb2eebd4

8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047 Summary: changed variable declaration type to byte* from long* to fix SIGBUS error Reviewed-by: ascarpino
author valeriep
date Wed, 20 Feb 2019 19:16:45 +0000
parents 23c77bdc49fc
children c52f29f8dd18
files src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c
diffstat 1 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c	Thu Jul 25 16:23:38 2019 +0100
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_keymgmt.c	Wed Feb 20 19:16:45 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  */
 
 /* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
@@ -151,14 +151,14 @@
     unsigned int i = 0U;
     unsigned long totalDataSize = 0UL, attributesCount = 0UL;
     unsigned long totalCkAttributesSize = 0UL, totalNativeKeyInfoArraySize = 0UL;
-    unsigned long* wrappedKeySizePtr = NULL;
+    jbyte* wrappedKeySizePtr = NULL;
     jbyte* nativeKeyInfoArrayRawCkAttributes = NULL;
     jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL;
     jbyte* nativeKeyInfoArrayRawDataPtr = NULL;
     CK_MECHANISM ckMechanism;
     char iv[16] = {0x0};
     CK_ULONG ckWrappedKeyLength = 0U;
-    unsigned long* wrappedKeySizeWrappedKeyArrayPtr = NULL;
+    jbyte* wrappedKeySizeWrappedKeyArrayPtr = NULL;
     CK_BYTE_PTR wrappedKeyBufferPtr = NULL;
     CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
     CK_OBJECT_CLASS class;
@@ -234,7 +234,7 @@
     //     * sizes are expressed in bytes and data type is unsigned long
     totalCkAttributesSize = attributesCount * sizeof(CK_ATTRIBUTE);
     TRACE1("DEBUG: GetNativeKeyInfo attributesCount = %lu\n", attributesCount);
-    TRACE1("DEBUG: GetNativeKeyInfo sizeof CK_ATTRIBUTE = %lu\n", sizeof(CK_ATTRIBUTE));
+    TRACE1("DEBUG: GetNativeKeyInfo sizeof CK_ATTRIBUTE = %zu\n", sizeof(CK_ATTRIBUTE));
     TRACE1("DEBUG: GetNativeKeyInfo totalCkAttributesSize = %lu\n", totalCkAttributesSize);
     TRACE1("DEBUG: GetNativeKeyInfo totalDataSize = %lu\n", totalDataSize);
 
@@ -254,8 +254,8 @@
         goto cleanup;
     }
 
-    wrappedKeySizePtr = (unsigned long*)(nativeKeyInfoArrayRaw +
-            sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize);
+    wrappedKeySizePtr = nativeKeyInfoArrayRaw +
+            sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize;
     memcpy(nativeKeyInfoArrayRaw, &totalCkAttributesSize, sizeof(unsigned long));
 
     memcpy(nativeKeyInfoArrayRaw + sizeof(unsigned long) + totalCkAttributesSize,
@@ -330,15 +330,15 @@
                 memcpy(nativeKeyInfoWrappedKeyArrayRaw, nativeKeyInfoArrayRaw,
                         totalNativeKeyInfoArraySize);
                 wrappedKeySizeWrappedKeyArrayPtr =
-                        (unsigned long*)(nativeKeyInfoWrappedKeyArrayRaw +
+                        nativeKeyInfoWrappedKeyArrayRaw +
                         sizeof(unsigned long)*2 + totalCkAttributesSize +
-                        totalDataSize);
+                        totalDataSize;
                 memcpy(wrappedKeySizeWrappedKeyArrayPtr, &ckWrappedKeyLength, sizeof(unsigned long));
                 TRACE1("DEBUG: GetNativeKeyInfo 1st C_WrapKey wrappedKeyLength = %lu\n", ckWrappedKeyLength);
 
                 wrappedKeyBufferPtr =
-                        (unsigned char*)wrappedKeySizeWrappedKeyArrayPtr +
-                        sizeof(unsigned long);
+                        (CK_BYTE_PTR) (wrappedKeySizeWrappedKeyArrayPtr +
+                        sizeof(unsigned long));
                 rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism,
                         jLongToCKULong(jWrappingKeyHandle),ckObjectHandle,
                         wrappedKeyBufferPtr, &ckWrappedKeyLength);
@@ -414,7 +414,7 @@
     jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL;
     jbyte* nativeKeyInfoArrayRawDataPtr = NULL;
     unsigned long totalDataSize = 0UL;
-    unsigned long* wrappedKeySizePtr = NULL;
+    jbyte* wrappedKeySizePtr = NULL;
     unsigned int i = 0U;
     CK_MECHANISM ckMechanism;
     char iv[16] = {0x0};
@@ -443,8 +443,8 @@
             sizeof(unsigned long));
     TRACE1("DEBUG: createNativeKey totalDataSize = %lu\n", totalDataSize);
 
-    wrappedKeySizePtr = (unsigned long*)(nativeKeyInfoArrayRaw +
-            sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize);
+    wrappedKeySizePtr = nativeKeyInfoArrayRaw +
+            sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize;
 
     memcpy(&ckWrappedKeyLength, wrappedKeySizePtr, sizeof(unsigned long));
     TRACE1("DEBUG: createNativeKey wrappedKeyLength = %lu\n", ckWrappedKeyLength);
@@ -470,7 +470,8 @@
         jMechanismToCKMechanism(env, jWrappingMech, &ckMechanism);
         rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, &ckMechanism,
                 jLongToCKULong(jWrappingKeyHandle),
-                (CK_BYTE_PTR)(wrappedKeySizePtr + 1), ckWrappedKeyLength,
+                (CK_BYTE_PTR)(wrappedKeySizePtr + sizeof(unsigned long)),
+                ckWrappedKeyLength,
                 (CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributes,
                 jLongToCKULong(nativeKeyInfoCkAttributesCount),
                 &ckObjectHandle);