Skip to content

Commit

Permalink
8282077: PKCS11 provider C_sign() impl should handle CKR_BUFFER_TOO_S…
Browse files Browse the repository at this point in the history
…MALL error

Backport-of: d7f31d0d53bfec627edc83ceb75fc6202891e186
  • Loading branch information
GoeLin committed May 10, 2023
1 parent 2995d08 commit 521833e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_sign.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
*/

/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
Expand Down Expand Up @@ -144,11 +144,22 @@ JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign

TRACE1("DEBUG C_Sign: ret rv=0x%lX\n", rv);

if (rv == CKR_BUFFER_TOO_SMALL) {
bufP = (CK_BYTE_PTR) malloc(ckSignatureLength);
if (bufP == NULL) {
throwOutOfMemoryError(env, 0);
goto cleanup;
}
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength,
bufP, &ckSignatureLength);
}

if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
jSignature = ckByteArrayToJByteArray(env, bufP, ckSignatureLength);
TRACE1("DEBUG C_Sign: signature length = %lu\n", ckSignatureLength);
}

cleanup:
free(ckpData);
if (bufP != BUF) { free(bufP); }

Expand Down

1 comment on commit 521833e

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