changeset 7254:cce840d5af0d

8001579: Cleanup warnings in security native code Reviewed-by: chegar, alanb, vinnie
author jzavgren
date Wed, 07 Nov 2012 10:49:19 +0000
parents 3cc793e4b177
children 754ed263fc3d
files src/share/native/sun/security/jgss/wrapper/GSSLibStub.c src/share/native/sun/security/jgss/wrapper/NativeUtil.c src/share/native/sun/security/pkcs11/wrapper/p11_convert.c src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c src/share/native/sun/security/pkcs11/wrapper/p11_digest.c src/share/native/sun/security/pkcs11/wrapper/p11_general.c src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c src/share/native/sun/security/pkcs11/wrapper/p11_sign.c src/share/native/sun/security/pkcs11/wrapper/p11_util.c src/solaris/native/sun/security/pkcs11/j2secmod_md.c src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c
diffstat 11 files changed, 100 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c	Wed Nov 07 10:49:19 2012 +0000
@@ -26,6 +26,7 @@
 #include "sun_security_jgss_wrapper_GSSLibStub.h"
 #include "NativeUtil.h"
 #include "NativeFunc.h"
+#include "jlong.h"
 
 /* Constants for indicating what type of info is needed for inqueries */
 const int TYPE_CRED_NAME = 10;
@@ -75,14 +76,14 @@
                                                      jclass jcls,
                                                      jbyteArray jbytes) {
   gss_OID cOid;
-  int i, len;
+  unsigned int i, len;
   jbyte* bytes;
   jthrowable gssEx;
   jboolean found;
 
   if (jbytes != NULL) {
     found = JNI_FALSE;
-    len = (*env)->GetArrayLength(env, jbytes) - 2;
+    len = (unsigned int)((*env)->GetArrayLength(env, jbytes) - 2);
     bytes = (*env)->GetByteArrayElements(env, jbytes, NULL);
     if (bytes != NULL) {
       for (i = 0; i < ftab->mechs->count; i++) {
@@ -98,9 +99,9 @@
     }
     if (found != JNI_TRUE) {
       checkStatus(env, NULL, GSS_S_BAD_MECH, 0, "[GSSLibStub_getMechPtr]");
-      return NULL;
-    } else return cOid;
-  } else return GSS_C_NO_OID;
+      return ptr_to_jlong(NULL);
+    } else return ptr_to_jlong(cOid);
+  } else return ptr_to_jlong(GSS_C_NO_OID);
 }
 
 
@@ -244,7 +245,7 @@
 
   if (ftab->inquireNamesForMech != NULL) {
 
-  mech = (gss_OID) (*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech);
+  mech = (gss_OID)jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
   nameTypes = GSS_C_NO_OID_SET;
 
   /* gss_inquire_names_for_mech(...) => N/A */
@@ -273,7 +274,7 @@
   OM_uint32 minor, major;
   gss_name_t nameHdl;
 
-  nameHdl = (gss_name_t) pName;
+  nameHdl = (gss_name_t) jlong_to_ptr(pName);
 
   sprintf(debugBuf, "[GSSLibStub_releaseName] %ld", (long) pName);
   debug(env, debugBuf);
@@ -319,7 +320,7 @@
   resetGSSBuffer(env, jnameVal, &nameVal);
 
   checkStatus(env, jobj, major, minor, "[GSSLibStub_importName]");
-  return (jlong) nameHdl;
+  return ptr_to_jlong(nameHdl);
 }
 
 
@@ -339,8 +340,8 @@
   int isEqual;
 
   isEqual = 0;
-  nameHdl1 = (gss_name_t) pName1;
-  nameHdl2 = (gss_name_t) pName2;
+  nameHdl1 = (gss_name_t) jlong_to_ptr(pName1);
+  nameHdl2 = (gss_name_t) jlong_to_ptr(pName2);
 
   sprintf(debugBuf, "[GSSLibStub_compareName] %ld %ld", (long) pName1,
     (long) pName2);
@@ -370,12 +371,12 @@
   gss_name_t nameHdl, mnNameHdl;
   gss_OID mech;
 
-  nameHdl = (gss_name_t) pName;
+  nameHdl = (gss_name_t) jlong_to_ptr(pName);
   sprintf(debugBuf, "[GSSLibStub_canonicalizeName] %ld", (long) pName);
   debug(env, debugBuf);
 
   if (nameHdl != GSS_C_NO_NAME) {
-    mech = (gss_OID) (*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech);
+    mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
     mnNameHdl = GSS_C_NO_NAME;
 
     /* gss_canonicalize_name(...) may return GSS_S_BAD_NAMETYPE,
@@ -391,7 +392,7 @@
     checkStatus(env, jobj, major, minor, "[GSSLibStub_canonicalizeName]");
   } else mnNameHdl = GSS_C_NO_NAME;
 
-  return (jlong) mnNameHdl;
+  return ptr_to_jlong(mnNameHdl);
 }
 
 /*
@@ -408,7 +409,7 @@
   gss_buffer_desc outBuf;
   jbyteArray jresult;
 
-  nameHdl = (gss_name_t) pName;
+  nameHdl = (gss_name_t) jlong_to_ptr(pName);
   sprintf(debugBuf, "[GSSLibStub_exportName] %ld", (long) pName);
   debug(env, debugBuf);
 
@@ -420,16 +421,16 @@
   if (major == GSS_S_NAME_NOT_MN) {
     debug(env, "[GSSLibStub_exportName] canonicalize and re-try");
 
-    mNameHdl = (gss_name_t)
+    mNameHdl = (gss_name_t)jlong_to_ptr(
         Java_sun_security_jgss_wrapper_GSSLibStub_canonicalizeName
-                                        (env, jobj, pName);
+                                        (env, jobj, pName));
     /* return immediately if an exception has occurred */
     if ((*env)->ExceptionCheck(env)) {
       return NULL;
     }
     major = (*ftab->exportName)(&minor, mNameHdl, &outBuf);
     Java_sun_security_jgss_wrapper_GSSLibStub_releaseName
-                                        (env, jobj, (jlong) mNameHdl);
+                                        (env, jobj, ptr_to_jlong(mNameHdl));
     /* return immediately if an exception has occurred */
     if ((*env)->ExceptionCheck(env)) {
       return NULL;
@@ -460,7 +461,7 @@
   jobject jtype;
   jobjectArray jresult;
 
-  nameHdl = (gss_name_t) pName;
+  nameHdl = (gss_name_t) jlong_to_ptr(pName);
   sprintf(debugBuf, "[GSSLibStub_displayName] %ld", (long) pName);
   debug(env, debugBuf);
 
@@ -512,10 +513,10 @@
   debug(env, "[GSSLibStub_acquireCred]");
 
 
-  mech = (gss_OID) (*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech);
+  mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
   mechs = newGSSOIDSet(env, mech);
   credUsage = (gss_cred_usage_t) usage;
-  nameHdl = (gss_name_t) pName;
+  nameHdl = (gss_name_t) jlong_to_ptr(pName);
   credHdl = GSS_C_NO_CREDENTIAL;
 
   sprintf(debugBuf, "[GSSLibStub_acquireCred] pName=%ld, usage=%d",
@@ -534,7 +535,7 @@
   debug(env, debugBuf);
 
   checkStatus(env, jobj, major, minor, "[GSSLibStub_acquireCred]");
-  return (jlong) credHdl;
+  return ptr_to_jlong(credHdl);
 }
 
 /*
@@ -550,9 +551,9 @@
   OM_uint32 minor, major;
   gss_cred_id_t credHdl;
 
-  credHdl = (gss_cred_id_t) pCred;
+  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
 
-  sprintf(debugBuf, "[GSSLibStub_releaseCred] %ld", pCred);
+  sprintf(debugBuf, "[GSSLibStub_releaseCred] %ld", (long int)pCred);
   debug(env, debugBuf);
 
   if (credHdl != GSS_C_NO_CREDENTIAL) {
@@ -562,7 +563,7 @@
 
     checkStatus(env, jobj, major, minor, "[GSSLibStub_releaseCred]");
   }
-  return (jlong) credHdl;
+  return ptr_to_jlong(credHdl);
 }
 
 /*
@@ -570,7 +571,7 @@
  */
 void inquireCred(JNIEnv *env, jobject jobj, gss_cred_id_t pCred,
                  jint type, void *result) {
-  OM_uint32 minor, major;
+  OM_uint32 minor, major=GSS_C_QOP_DEFAULT;
   OM_uint32 routineErr;
   gss_cred_id_t credHdl;
 
@@ -617,9 +618,9 @@
   gss_name_t nameHdl;
   gss_cred_id_t credHdl;
 
-  credHdl = (gss_cred_id_t) pCred;
+  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
 
-  sprintf(debugBuf, "[GSSLibStub_getCredName] %ld", pCred);
+  sprintf(debugBuf, "[GSSLibStub_getCredName] %ld", (long int)pCred);
   debug(env, debugBuf);
 
   nameHdl = GSS_C_NO_NAME;
@@ -633,7 +634,7 @@
   sprintf(debugBuf, "[GSSLibStub_getCredName] pName=%ld", (long) nameHdl);
   debug(env, debugBuf);
 
-  return (jlong) nameHdl;
+  return ptr_to_jlong(nameHdl);
 }
 
 /*
@@ -649,9 +650,9 @@
   gss_cred_id_t credHdl;
   OM_uint32 lifetime;
 
-  credHdl = (gss_cred_id_t) pCred;
+  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
 
-  sprintf(debugBuf, "[GSSLibStub_getCredTime] %ld", pCred);
+  sprintf(debugBuf, "[GSSLibStub_getCredTime] %ld", (long int)pCred);
   debug(env, debugBuf);
 
   lifetime = 0;
@@ -677,9 +678,9 @@
   gss_cred_usage_t usage;
   gss_cred_id_t credHdl;
 
-  credHdl = (gss_cred_id_t) pCred;
+  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
 
-  sprintf(debugBuf, "[GSSLibStub_getCredUsage] %ld", pCred);
+  sprintf(debugBuf, "[GSSLibStub_getCredUsage] %ld", (long int)pCred);
   debug(env, debugBuf);
 
   inquireCred(env, jobj, credHdl, TYPE_CRED_USAGE, &usage);
@@ -738,13 +739,13 @@
     return NULL;
   }
 
-  mech2 = (gss_OID) (*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech);
+  mech2 = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
 
   if (sameMech(env, mech, mech2) == JNI_TRUE) {
     /* mech match - return the context object */
     return (*env)->NewObject(env, CLS_NativeGSSContext,
                                  MID_NativeGSSContext_ctor,
-                                 (jlong) contextHdl, jobj);
+                                 ptr_to_jlong(contextHdl), jobj);
   } else {
     /* mech mismatch - clean up then return null */
     major = (*ftab->deleteSecContext)(&minor, &contextHdl, GSS_C_NO_BUFFER);
@@ -784,11 +785,11 @@
 */
   debug(env, "[GSSLibStub_initContext]");
 
-  credHdl = (gss_cred_id_t) pCred;
-  contextHdl = (gss_ctx_id_t)
-    (*env)->GetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext);
-  targetName = (gss_name_t) pName;
-  mech = (gss_OID) (*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech);
+  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(
+    (*env)->GetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext));
+  targetName = (gss_name_t) jlong_to_ptr(pName);
+  mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech));
   flags = (OM_uint32) (*env)->GetIntField(env, jcontextSpi,
                                           FID_NativeGSSContext_flags);
   time = getGSSTime((*env)->GetIntField(env, jcontextSpi,
@@ -821,7 +822,7 @@
   if (GSS_ERROR(major) == GSS_S_COMPLETE) {
     /* update member values if needed */
     (*env)->SetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext,
-                        (jlong) contextHdl);
+                        ptr_to_jlong(contextHdl));
     (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_flags, aFlags);
     sprintf(debugBuf, "[GSSLibStub_initContext] set flags=0x%x", aFlags);
     debug(env, debugBuf);
@@ -879,7 +880,7 @@
   OM_uint32 aFlags;
   OM_uint32 aTime;
   gss_cred_id_t delCred;
-  jobject jsrcName;
+  jobject jsrcName=GSS_C_NO_NAME;
   jobject jdelCred;
   jobject jMech;
   jbyteArray jresult;
@@ -889,9 +890,9 @@
 
   debug(env, "[GSSLibStub_acceptContext]");
 
-  contextHdl = (gss_ctx_id_t)
-    (*env)->GetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext);
-  credHdl = (gss_cred_id_t) pCred;
+  contextHdl = (gss_ctx_id_t)jlong_to_ptr(
+    (*env)->GetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext));
+  credHdl = (gss_cred_id_t) jlong_to_ptr(pCred);
   initGSSBuffer(env, jinToken, &inToken);
   cb = getGSSCB(env, jcb);
   srcName = GSS_C_NO_NAME;
@@ -922,7 +923,7 @@
   if (GSS_ERROR(major) == GSS_S_COMPLETE) {
     /* update member values if needed */
     (*env)->SetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext,
-                        (jlong) contextHdl);
+                        ptr_to_jlong(contextHdl));
     sprintf(debugBuf, "[GSSLibStub_acceptContext] set pContext=%ld",
             (long)contextHdl);
     debug(env, debugBuf);
@@ -940,7 +941,7 @@
                               NULL, NULL);
       jtargetName = (*env)->NewObject(env, CLS_GSSNameElement,
                                 MID_GSSNameElement_ctor,
-                                (jlong) targetName, jobj);
+                                ptr_to_jlong(targetName), jobj);
 
       /* return immediately if an exception has occurred */
       if ((*env)->ExceptionCheck(env)) {
@@ -955,7 +956,7 @@
     if (srcName != GSS_C_NO_NAME) {
       jsrcName = (*env)->NewObject(env, CLS_GSSNameElement,
                                    MID_GSSNameElement_ctor,
-                                   (jlong) srcName, jobj);
+                                   ptr_to_jlong(srcName), jobj);
       /* return immediately if an exception has occurred */
       if ((*env)->ExceptionCheck(env)) {
         return NULL;
@@ -981,7 +982,7 @@
       if (delCred != GSS_C_NO_CREDENTIAL) {
         jdelCred = (*env)->NewObject(env, CLS_GSSCredElement,
                                      MID_GSSCredElement_ctor,
-                                     (jlong) delCred, jsrcName, jMech);
+                                     ptr_to_jlong(delCred), jsrcName, jMech);
         /* return immediately if an exception has occurred */
         if ((*env)->ExceptionCheck(env)) {
           return NULL;
@@ -1031,7 +1032,7 @@
   jlong result[6];
   jlongArray jresult;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
 
   sprintf(debugBuf, "[GSSLibStub_inquireContext] %ld", (long)contextHdl);
   debug(env, debugBuf);
@@ -1051,8 +1052,8 @@
                                                 (long)targetName);
   debug(env, debugBuf);
 
-  result[0] = (jlong) srcName;
-  result[1] = (jlong) targetName;
+  result[0] = ptr_to_jlong(srcName);
+  result[1] = ptr_to_jlong(targetName);
   result[2] = (jlong) isInitiator;
   result[3] = (jlong) isEstablished;
   result[4] = (jlong) flags;
@@ -1081,9 +1082,9 @@
   gss_OID mech;
   gss_ctx_id_t contextHdl;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
 
-  sprintf(debugBuf, "[GSSLibStub_getContextMech] %ld", pContext);
+  sprintf(debugBuf, "[GSSLibStub_getContextMech] %ld", (long int)pContext);
   debug(env, debugBuf);
 
   major = (*ftab->inquireContext)(&minor, contextHdl, NULL, NULL,
@@ -1111,7 +1112,7 @@
   gss_name_t nameHdl;
   gss_ctx_id_t contextHdl;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
 
   sprintf(debugBuf, "[GSSLibStub_getContextName] %ld, isSrc=%d",
           (long)contextHdl, isSrc);
@@ -1129,13 +1130,13 @@
   checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireContextAll]");
   /* return immediately if an exception has occurred */
   if ((*env)->ExceptionCheck(env)) {
-    return (long)NULL;
+    return ptr_to_jlong(NULL);
   }
 
   sprintf(debugBuf, "[GSSLibStub_getContextName] pName=%ld", (long) nameHdl);
   debug(env, debugBuf);
 
-  return (jlong) nameHdl;
+  return ptr_to_jlong(nameHdl);
 }
 
 /*
@@ -1151,7 +1152,7 @@
   gss_ctx_id_t contextHdl;
   OM_uint32 time;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_getContextTime] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
@@ -1180,17 +1181,17 @@
   OM_uint32 minor, major;
   gss_ctx_id_t contextHdl;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_deleteContext] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
-  if (contextHdl == GSS_C_NO_CONTEXT) return GSS_C_NO_CONTEXT;
+  if (contextHdl == GSS_C_NO_CONTEXT) return ptr_to_jlong(GSS_C_NO_CONTEXT);
 
   /* gss_delete_sec_context(...) => GSS_S_NO_CONTEXT(!) */
   major = (*ftab->deleteSecContext)(&minor, &contextHdl, GSS_C_NO_BUFFER);
 
   checkStatus(env, jobj, major, minor, "[GSSLibStub_deleteContext]");
-  return (jlong) contextHdl;
+  return (jlong) ptr_to_jlong(contextHdl);
 }
 
 /*
@@ -1211,7 +1212,7 @@
   OM_uint32 outSize, maxInSize;
   gss_qop_t qop;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_wrapSizeLimit] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
@@ -1244,7 +1245,7 @@
   gss_buffer_desc interProcToken;
   jbyteArray jresult;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_exportContext] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
@@ -1281,7 +1282,7 @@
   gss_buffer_desc msgToken;
   jbyteArray jresult;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_getMic] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
@@ -1290,7 +1291,7 @@
     checkStatus(env, jobj, GSS_S_CONTEXT_EXPIRED, 0, "[GSSLibStub_getMic]");
     return NULL;
   }
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   qop = (gss_qop_t) jqop;
   initGSSBuffer(env, jmsg, &msg);
 
@@ -1326,7 +1327,7 @@
   gss_buffer_desc msgToken;
   gss_qop_t qop;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_verifyMic] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
@@ -1376,7 +1377,7 @@
   gss_ctx_id_t contextHdl;
   jbyteArray jresult;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_wrap] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
@@ -1427,7 +1428,7 @@
   gss_qop_t qop;
   jbyteArray jresult;
 
-  contextHdl = (gss_ctx_id_t) pContext;
+  contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
   sprintf(debugBuf, "[GSSLibStub_unwrap] %ld", (long)contextHdl);
   debug(env, debugBuf);
 
--- a/src/share/native/sun/security/jgss/wrapper/NativeUtil.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/jgss/wrapper/NativeUtil.c	Wed Nov 07 10:49:19 2012 +0000
@@ -25,6 +25,7 @@
 
 #include "NativeUtil.h"
 #include "NativeFunc.h"
+#include "jlong.h"
 
 const int JAVA_DUPLICATE_TOKEN_CODE = 19; /* DUPLICATE_TOKEN */
 const int JAVA_OLD_TOKEN_CODE = 20; /* OLD_TOKEN */
@@ -412,7 +413,7 @@
   OM_uint32 result;
 
   /* special handle values equal to JAVA_MAX */
-  if (jtime == JAVA_MAX) {
+  if (jtime == (jint)JAVA_MAX) {
     result = GSS_C_INDEFINITE;
   } else {
     result = jtime;
@@ -482,7 +483,7 @@
 
   messageContext = 0;
   if (jstub != NULL) {
-    mech = (gss_OID) (*env)->GetLongField(env, jstub, FID_GSSLibStub_pMech);
+    mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jstub, FID_GSSLibStub_pMech));
   } else {
     mech = GSS_C_NO_OID;
   }
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c	Wed Nov 07 10:49:19 2012 +0000
@@ -422,6 +422,7 @@
     jfieldID jFieldID;
     jlong jType;
     jobject jPValue;
+    memset(&ckAttribute, 0, sizeof(CK_ATTRIBUTE));
 
     // TBD: what if jAttribute == NULL?!
 
@@ -1577,6 +1578,7 @@
     CK_RSA_PKCS_PSS_PARAMS ckParam;
     jfieldID fieldID;
     jlong jHashAlg, jMgf, jSLen;
+    memset(&ckParam, 0, sizeof(CK_RSA_PKCS_PSS_PARAMS));
 
     /* get hashAlg */
     jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS);
@@ -1617,6 +1619,7 @@
     jfieldID fieldID;
     jlong jLong;
     jobject jSharedData, jPublicData;
+    memset(&ckParam, 0, sizeof(CK_ECDH1_DERIVE_PARAMS));
 
     /* get kdf */
     jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS);
@@ -1663,6 +1666,7 @@
     jfieldID fieldID;
     jlong jKdf, jPrivateDataLen, jPrivateData;
     jobject jSharedData, jPublicData, jPublicData2;
+    memset(&ckParam, 0, sizeof(CK_ECDH2_DERIVE_PARAMS));
 
     /* get kdf */
     jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS);
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c	Wed Nov 07 10:49:19 2012 +0000
@@ -180,14 +180,14 @@
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
     if (directIn != 0) {
-      inBufP = (CK_BYTE_PTR) directIn;
+      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
     } else {
       inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
       if (inBufP == NULL) { return 0; }
     }
 
     if (directOut != 0) {
-      outBufP = (CK_BYTE_PTR) directOut;
+      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
     } else {
       outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
       if (outBufP == NULL) {
@@ -249,7 +249,7 @@
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
     if (directOut != 0) {
-      outBufP = (CK_BYTE_PTR) directOut;
+      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
     } else {
       outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
       if (outBufP == NULL) { return 0; }
@@ -401,14 +401,14 @@
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
     if (directIn != 0) {
-      inBufP = (CK_BYTE_PTR) directIn;
+      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
     } else {
       inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
       if (inBufP == NULL) { return 0; }
     }
 
     if (directOut != 0) {
-      outBufP = (CK_BYTE_PTR) directOut;
+      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
     } else {
       outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
       if (outBufP == NULL) {
@@ -465,7 +465,7 @@
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
     if (directOut != 0) {
-      outBufP = (CK_BYTE_PTR) directOut;
+      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
     } else {
       outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
       if (outBufP == NULL) { return 0; }
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_digest.c	Wed Nov 07 10:49:19 2012 +0000
@@ -51,6 +51,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include "jlong.h"
 
 #include "sun_security_pkcs11_wrapper_PKCS11.h"
 
@@ -178,7 +179,7 @@
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
     if (directIn != 0) {
-        rv = (*ckpFunctions->C_DigestUpdate)(ckSessionHandle, (CK_BYTE_PTR)directIn, jInLen);
+        rv = (*ckpFunctions->C_DigestUpdate)(ckSessionHandle, (CK_BYTE_PTR)jlong_to_ptr(directIn), jInLen);
         ckAssertReturnValueOK(env, rv);
         return;
     }
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_general.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_general.c	Wed Nov 07 10:49:19 2012 +0000
@@ -250,10 +250,12 @@
 (JNIEnv *env, jobject obj)
 {
     CK_INFO ckLibInfo;
-    jobject jInfoObject;
+    jobject jInfoObject=NULL;
     CK_RV rv;
+    CK_FUNCTION_LIST_PTR ckpFunctions;
+    memset(&ckLibInfo, 0, sizeof(CK_INFO));
 
-    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
+    ckpFunctions = getFunctionList(env, obj);
     if (ckpFunctions == NULL) { return NULL; }
 
     rv = (*ckpFunctions->C_GetInfo)(&ckLibInfo);
@@ -381,7 +383,7 @@
 {
     CK_SLOT_ID ckSlotID;
     CK_SLOT_INFO ckSlotInfo;
-    jobject jSlotInfoObject;
+    jobject jSlotInfoObject=NULL;
     CK_RV rv;
 
     CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
@@ -393,7 +395,7 @@
     if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
         jSlotInfoObject = ckSlotInfoPtrToJSlotInfo(env, &ckSlotInfo);
     }
-    return jSlotInfoObject ;
+    return jSlotInfoObject;
 }
 
 /*
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sessmgmt.c	Wed Nov 07 10:49:19 2012 +0000
@@ -256,7 +256,7 @@
 {
     CK_SESSION_HANDLE ckSessionHandle;
     CK_SESSION_INFO ckSessionInfo;
-    jobject jSessionInfo;
+    jobject jSessionInfo=NULL;
     CK_RV rv;
 
     CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_sign.c	Wed Nov 07 10:49:19 2012 +0000
@@ -51,6 +51,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include "jlong.h"
 
 #include "sun_security_pkcs11_wrapper_PKCS11.h"
 
@@ -198,7 +199,7 @@
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
     if (directIn != 0) {
-        rv = (*ckpFunctions->C_SignUpdate)(ckSessionHandle, (CK_BYTE_PTR)directIn, jInLen);
+        rv = (*ckpFunctions->C_SignUpdate)(ckSessionHandle, (CK_BYTE_PTR) jlong_to_ptr(directIn), jInLen);
         ckAssertReturnValueOK(env, rv);
         return;
     }
@@ -262,7 +263,7 @@
 
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
-    if ((jExpectedLength > 0) && (jExpectedLength < ckSignatureLength)) {
+    if ((jExpectedLength > 0) && ((CK_ULONG)jExpectedLength < ckSignatureLength)) {
         ckSignatureLength = jExpectedLength;
     }
 
@@ -496,7 +497,7 @@
     ckSessionHandle = jLongToCKULong(jSessionHandle);
 
     if (directIn != 0) {
-        rv = (*ckpFunctions->C_VerifyUpdate)(ckSessionHandle, (CK_BYTE_PTR)directIn, jInLen);
+        rv = (*ckpFunctions->C_VerifyUpdate)(ckSessionHandle, (CK_BYTE_PTR)jlong_to_ptr(directIn), jInLen);
         ckAssertReturnValueOK(env, rv);
         return;
     }
--- a/src/share/native/sun/security/pkcs11/wrapper/p11_util.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/share/native/sun/security/pkcs11/wrapper/p11_util.c	Wed Nov 07 10:49:19 2012 +0000
@@ -106,7 +106,7 @@
     if (moduleData == NULL) {
         return ;
     }
-    (*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, (jlong)moduleData);
+    (*env)->SetLongField(env, pkcs11Implementation, pNativeDataID, ptr_to_jlong(moduleData));
 }
 
 
@@ -120,7 +120,7 @@
         return NULL;
     }
     jData = (*env)->GetLongField(env, pkcs11Implementation, pNativeDataID);
-    return (ModuleData*)jData;
+    return (ModuleData*)jlong_to_ptr(jData);
 }
 
 CK_FUNCTION_LIST_PTR getFunctionList(JNIEnv *env, jobject pkcs11Implementation) {
--- a/src/solaris/native/sun/security/pkcs11/j2secmod_md.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/solaris/native/sun/security/pkcs11/j2secmod_md.c	Wed Nov 07 10:49:19 2012 +0000
@@ -34,7 +34,7 @@
 #include "j2secmod.h"
 
 void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName) {
-    void *hModule = (void*)jHandle;
+    void *hModule = (void*)jlong_to_ptr(jHandle);
     void *fAddress = dlsym(hModule, functionName);
     if (fAddress == NULL) {
         char errorMessage[256];
@@ -53,7 +53,7 @@
     void *hModule = dlopen(libName, RTLD_NOLOAD);
     dprintf2("-handle for %s: %u\n", libName, hModule);
     (*env)->ReleaseStringUTFChars(env, jLibName, libName);
-    return (jlong)hModule;
+    return ptr_to_jlong(hModule);
 }
 
 JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_Secmod_nssLoadLibrary
@@ -72,5 +72,5 @@
         return 0;
     }
 
-    return (jlong)hModule;
+    return ptr_to_jlong(hModule);
 }
--- a/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c	Thu Jan 23 23:19:20 2014 +0000
+++ b/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c	Wed Nov 07 10:49:19 2012 +0000
@@ -79,7 +79,7 @@
 {
     void *hModule;
     char *error;
-    CK_C_GetFunctionList C_GetFunctionList;
+    CK_C_GetFunctionList C_GetFunctionList=NULL;
     CK_RV rv;
     ModuleData *moduleData;
     jobject globalPKCS11ImplementationReference;