Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_keymgmt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
*/

/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
Expand Down Expand Up @@ -929,6 +929,12 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey
rv = (*ckpFunctions->C_DeriveKey)(ckSessionHandle, ckpMechanism, ckBaseKeyHandle,
ckpAttributes, ckAttributesLength, phKey);

/* If derivation failed, do not attempt copy-back */
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) {
jKeyHandle = 0L;
goto cleanup;
}

jKeyHandle = ckLongToJLong(ckKeyHandle);

switch (ckpMechanism->mechanism) {
Expand Down Expand Up @@ -956,8 +962,9 @@ JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey
// empty
break;
}
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) {
jKeyHandle =0L;
/* Do not continue if any copy-back operation raised an exception */
if ((*env)->ExceptionCheck(env)) {
goto cleanup;
}

cleanup:
Expand Down