diff --git a/closed/src/java.base/share/native/libjncrypto/NativeCrypto.c b/closed/src/java.base/share/native/libjncrypto/NativeCrypto.c index 392c5cd6c40..229a30dc77a 100644 --- a/closed/src/java.base/share/native/libjncrypto/NativeCrypto.c +++ b/closed/src/java.base/share/native/libjncrypto/NativeCrypto.c @@ -631,6 +631,9 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath) * Since there is no indication of the version of a symlink, * they have to be loaded first, so as to compare with other * available options. + * Note: On macOS 11 or later, loading the general symlink causes + * a fatal warning and associated abort by default, so it is + * commented out and not used. * * The rest of the libraries are listed in descending order, * which allows us to do two things: @@ -653,8 +656,7 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath) "libcrypto.so.1.1", /* 1.1.x library name */ "libcrypto.so.1.0.0", /* 1.0.x library name */ #elif defined(__APPLE__) /* defined(_AIX) */ - /* "libcrypto.dylib" In MacOS 11 or later, loading this symlink causes a - fatal warning and associated abort by default. */ + /* "libcrypto.dylib" general symlink library name */ "libcrypto.3.dylib", /* 3.x library name */ "libcrypto.1.1.dylib", /* 1.1.x library name */ "libcrypto.1.0.0.dylib", /* 1.0.x library name */ @@ -791,7 +793,14 @@ Java_jdk_crypto_jniprovider_NativeCrypto_loadCrypto jlong ossl_ver = 0; if (NULL != jlibname) { - clibname = (*env)->GetStringUTFChars(env, jlibname, NULL); + const char *clibname = (*env)->GetStringUTFChars(env, jlibname, NULL); + if (NULL == clibname) { + if (traceEnabled) { + fprintf(stderr, "Failed to get jdk.native.openssl.lib value.\n"); + fflush(stderr); + } + return -1; + } if ('\0' == clibname[0]) { if (traceEnabled) { fprintf(stderr, "The jdk.native.openssl.lib property is not set.\n"); @@ -804,13 +813,22 @@ Java_jdk_crypto_jniprovider_NativeCrypto_loadCrypto fprintf(stderr, "OpenSSL library specified in jdk.openssl.lib couldn't be loaded.\n"); fflush(stderr); } + (*env)->ReleaseStringUTFChars(env, jlibname, clibname); return -1; } } + (*env)->ReleaseStringUTFChars(env, jlibname, clibname); } if (NULL != jhomepath) { chomepath = (*env)->GetStringUTFChars(env, jhomepath, NULL); + if (NULL == chomepath) { + if (traceEnabled) { + fprintf(stderr, "Failed to get java.home value.\n"); + fflush(stderr); + } + return -1; + } } /* If the jdk.native.openssl.lib property was not set, attempt @@ -820,8 +838,9 @@ Java_jdk_crypto_jniprovider_NativeCrypto_loadCrypto crypto_library = find_crypto_library(traceEnabled, chomepath); } - (*env)->ReleaseStringUTFChars(env, jlibname, clibname); - (*env)->ReleaseStringUTFChars(env, jhomepath, chomepath); + if (NULL != jhomepath) { + (*env)->ReleaseStringUTFChars(env, jhomepath, chomepath); + } /* If an OpenSSL library was not loaded from any of the potential * sources, fail loading native crypto.