8068024: Null pointer dereference in jdk/src/macosx/native/apple/security/KeystoreImpl.m
authorigerasim
Wed, 22 Nov 2017 16:31:28 -0800
changeset 47925 6493e5ed2bd9
parent 47924 90f4803a2663
child 47926 c5ad58d25a0d
8068024: Null pointer dereference in jdk/src/macosx/native/apple/security/KeystoreImpl.m Reviewed-by: weijun
src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m
--- a/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m	Wed Nov 22 23:31:37 2017 +0000
+++ b/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m	Wed Nov 22 16:31:28 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
  */
 
 #import "apple_security_KeychainStore.h"
+#import "jni_util.h"
 
 #import <Security/Security.h>
 #import <Security/SecImportExport.h>
@@ -52,6 +53,11 @@
     }
 
     attribCString = malloc(itemAttrs[0].length + 1);
+    if (attribCString == NULL) {
+        JNU_ThrowOutOfMemoryError(env, "native heap");
+        goto errOut;
+    }
+
     strncpy(attribCString, itemAttrs[0].data, itemAttrs[0].length);
     attribCString[itemAttrs[0].length] = '\0';
     returnValue = (*env)->NewStringUTF(env, attribCString);
@@ -478,6 +484,8 @@
     // again later as a certificate.
     addIdentitiesToKeystore(env, this);
 
+    JNU_CHECK_EXCEPTION(env);
+
     // Scan current keychain for trusted certificates.
     addCertificatesToKeystore(env, this);