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

Backport-of: d1c6cd104e
This commit is contained in:
Martin Doerr
2024-06-20 10:02:35 +00:00
committed by Vitaly Provodin
parent b2221facb3
commit 398329a4b6
2 changed files with 7 additions and 8 deletions

View File

@@ -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;

View File

@@ -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;