Skip to content

Commit

Permalink
8330133: libj2pkcs11.so crashes on some pkcs#11 v3.0 libraries
Browse files Browse the repository at this point in the history
Reviewed-by: djelinski, weijun
  • Loading branch information
Valerie Peng committed Apr 16, 2024
1 parent 76cbe48 commit d1c6cd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/jdk.crypto.cryptoki/unix/native/libj2pkcs11/p11_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -210,15 +210,13 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
}
} 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;
Expand Down
7 changes: 4 additions & 3 deletions src/jdk.crypto.cryptoki/windows/native/libj2pkcs11/p11_md.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -234,7 +234,8 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
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;
Expand Down

1 comment on commit d1c6cd1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.