changeset 10261:5a29fd30ffaa

8034031: [parfait] JNI exception pending in jdk/src/macosx/native/apple/security/KeystoreImpl.m Reviewed-by: alanb, weijun
author vinnie
date Fri, 14 Nov 2014 14:12:58 +0000
parents b0139e9a4bdd
children 31dac938108d
files src/macosx/native/apple/security/KeystoreImpl.m
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/native/apple/security/KeystoreImpl.m	Fri Nov 14 15:03:47 2014 +0300
+++ b/src/macosx/native/apple/security/KeystoreImpl.m	Fri Nov 14 14:12:58 2014 +0000
@@ -299,11 +299,21 @@
 
             // Make a java array of certificate data from the chain.
             jclass byteArrayClass = (*env)->FindClass(env, "[B");
+            if (byteArrayClass == NULL) {
+                goto errOut;
+            }
             jobjectArray javaCertArray = (*env)->NewObjectArray(env, certCount, byteArrayClass, NULL);
+            // Cleanup first then check for a NULL return code
             (*env)->DeleteLocalRef(env, byteArrayClass);
+            if (javaCertArray == NULL) {
+                goto errOut;
+            }
 
             // And, make an array of the certificate refs.
             jlongArray certRefArray = (*env)->NewLongArray(env, certCount);
+            if (certRefArray == NULL) {
+                goto errOut;
+            }
 
             SecCertificateRef currCertRef = NULL;
 
@@ -318,6 +328,9 @@
                 bzero(&currCertData, sizeof(CSSM_DATA));
                 err = SecCertificateGetData(currCertRef, &currCertData);
                 jbyteArray encodedCertData = (*env)->NewByteArray(env, currCertData.Length);
+                if (encodedCertData == NULL) {
+                    goto errOut;
+                }
                 (*env)->SetByteArrayRegion(env, encodedCertData, 0, currCertData.Length, (jbyte *)currCertData.Data);
                 (*env)->SetObjectArrayElement(env, javaCertArray, i, encodedCertData);
                 jlong certRefElement = ptr_to_jlong(currCertRef);
@@ -330,6 +343,9 @@
 
             // Find the label.  It's a 'blob', but we interpret as characters.
             jstring alias = getLabelFromItem(env, (SecKeychainItemRef)certificate);
+            if (alias == NULL) {
+                goto errOut;
+            }
 
             // Find the creation date.
             jlong creationDate = getModDateFromItem(env, (SecKeychainItemRef)certificate);
@@ -340,6 +356,7 @@
         }
     } while (searchResult == noErr);
 
+errOut:
     if (identitySearch != NULL) {
         CFRelease(identitySearch);
     }
@@ -362,10 +379,16 @@
             CSSM_DATA currCertificate;
             err = SecCertificateGetData(certRef, &currCertificate);
             jbyteArray certData = (*env)->NewByteArray(env, currCertificate.Length);
+            if (certData == NULL) {
+                goto errOut;
+            }
             (*env)->SetByteArrayRegion(env, certData, 0, currCertificate.Length, (jbyte *)currCertificate.Data);
 
             // Find the label.  It's a 'blob', but we interpret as characters.
             jstring alias = getLabelFromItem(env, theItem);
+            if (alias == NULL) {
+                goto errOut;
+            }
 
             // Find the creation date.
             jlong creationDate = getModDateFromItem(env, theItem);
@@ -376,6 +399,7 @@
         }
     } while (searchResult == noErr);
 
+errOut:
     if (keychainItemSearch != NULL) {
         CFRelease(keychainItemSearch);
     }
@@ -404,6 +428,9 @@
 
         if (passwordLen > 0) {
             passwordChars = (*env)->GetCharArrayElements(env, passwordObj, NULL);
+            if (passwordChars == NULL) {
+                goto errOut;
+            }
             passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
         }
     }
@@ -423,9 +450,13 @@
     if (err == noErr) {
         CFIndex size = CFDataGetLength(exportedData);
         returnValue = (*env)->NewByteArray(env, size);
+        if (returnValue == NULL) {
+            goto errOut;
+        }
         (*env)->SetByteArrayRegion(env, returnValue, 0, size, (jbyte *)CFDataGetBytePtr(exportedData));
     }
 
+errOut:
     if (exportedData) CFRelease(exportedData);
     if (passwordStrRef) CFRelease(passwordStrRef);
 
@@ -466,6 +497,9 @@
 
     jsize dataSize = (*env)->GetArrayLength(env, rawDataObj);
     jbyte *rawData = (*env)->GetByteArrayElements(env, rawDataObj, NULL);
+    if (rawData == NULL) {
+        goto errOut;
+    }
 
     CFDataRef cfDataToImport = CFDataCreate(kCFAllocatorDefault, (UInt8 *)rawData, dataSize);
     CFArrayRef createdItems = NULL;
@@ -522,6 +556,8 @@
         CFRelease(createdItems);
     }
 
+errOut: ;
+
 JNF_COCOA_EXIT(env);
 
     return returnValue;