8330133: libj2pkcs11.so crashes on some pkcs#11 v3.0 libraries

Reviewed-by: djelinski, weijun
This commit is contained in:
Valerie Peng 2024-04-16 22:47:02 +00:00
parent 76cbe4883b
commit d1c6cd104e
2 changed files with 7 additions and 8 deletions
src/jdk.crypto.cryptoki
unix/native/libj2pkcs11
windows/native/libj2pkcs11

@ -162,7 +162,7 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
rv = (C_GetInterface)(NULL, NULL, &interface, 0L);
// don't use ckAssertReturnValueOK as we want to continue trying
// C_GetFunctionList() or method named by "getFunctionListStr"
if (rv == CKR_OK) {
if (rv == CKR_OK && interface != NULL) {
goto setModuleData;
}
}
@ -210,15 +210,13 @@ setModuleData:
}
} else if (interface != NULL) {
moduleData->ckFunctionListPtr = interface->pFunctionList;
if (((CK_VERSION *)moduleData->ckFunctionListPtr)->major == 3) {
moduleData->ckFunctionList30Ptr = interface->pFunctionList;
}
} else {
// should never happen
p11ThrowIOException(env, "ERROR: No function list ptr found");
goto cleanup;
}
if (((CK_VERSION *)moduleData->ckFunctionListPtr)->major == 3) {
if (((CK_VERSION *)moduleData->ckFunctionListPtr)->major == 3 &&
interface != NULL) {
moduleData->ckFunctionList30Ptr = interface->pFunctionList;
} else {
moduleData->ckFunctionList30Ptr = NULL;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@ -186,7 +186,7 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
if (C_GetInterface != NULL) {
TRACE0("Connect: Found C_GetInterface func\n");
rv = (C_GetInterface)(NULL, NULL, &interface, 0);
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
if (rv == CKR_OK && interface != NULL) {
goto setModuleData;
}
}
@ -234,7 +234,8 @@ setModuleData:
p11ThrowIOException(env, "ERROR: No function list ptr found");
goto cleanup;
}
if (((CK_VERSION *)moduleData->ckFunctionListPtr)->major == 3) {
if (((CK_VERSION *)moduleData->ckFunctionListPtr)->major == 3 &&
interface != NULL) {
moduleData->ckFunctionList30Ptr = interface->pFunctionList;
} else {
moduleData->ckFunctionList30Ptr = NULL;