changeset 48113:6493e5ed2bd9

8068024: Null pointer dereference in jdk/src/macosx/native/apple/security/KeystoreImpl.m Reviewed-by: weijun
author igerasim
date Wed, 22 Nov 2017 16:31:28 -0800
parents 90f4803a2663
children c5ad58d25a0d
files src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);