--- a/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m Mon Sep 04 19:33:44 2017 +0100
+++ b/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m Tue Sep 05 15:53:33 2017 +0100
@@ -439,6 +439,11 @@
goto errOut;
}
passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
+
+ // clear the password and release
+ memset(passwordChars, 0, passwordLen);
+ (*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars,
+ JNI_ABORT);
}
}
@@ -527,8 +532,19 @@
if (passwordObj) {
passwordLen = (*env)->GetArrayLength(env, passwordObj);
- passwordChars = (*env)->GetCharArrayElements(env, passwordObj, NULL);
- passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
+
+ if (passwordLen > 0) {
+ passwordChars = (*env)->GetCharArrayElements(env, passwordObj, NULL);
+ if (passwordChars == NULL) {
+ goto errOut;
+ }
+ passwordStrRef = CFStringCreateWithCharacters(kCFAllocatorDefault, passwordChars, passwordLen);
+
+ // clear the password and release
+ memset(passwordChars, 0, passwordLen);
+ (*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars,
+ JNI_ABORT);
+ }
}
paramBlock.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;