Skip to content

Commit 760cb04

Browse files
martinuyfranferrax
andcommittedJun 8, 2023
8309569: sun/security/pkcs11/Signature/TestRSAKeyLength.java fails after JDK-8301553
Co-authored-by: Martin Balao <mbalao@openjdk.org> Co-authored-by: Francisco Ferrari Bihurriet <fferrari@redhat.com> Reviewed-by: valeriep
1 parent e8a5984 commit 760cb04

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed
 

‎src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_util.c

+33-28
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,14 @@ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBO
536536
jboolean* jpTemp;
537537
CK_ULONG i;
538538

539-
*ckpLength = jArray == NULL ? 0L : (*env)->GetArrayLength(env, jArray);
540-
if(*ckpLength == 0L) {
539+
if (jArray == NULL) {
541540
*ckpArray = NULL_PTR;
541+
*ckpLength = 0UL;
542542
return;
543543
}
544+
*ckpLength = (*env)->GetArrayLength(env, jArray);
544545
jpTemp = (jboolean*) calloc(*ckpLength, sizeof(jboolean));
545-
if (jpTemp == NULL) {
546+
if (jpTemp == NULL && *ckpLength != 0UL) {
546547
p11ThrowOutOfMemoryError(env, 0);
547548
return;
548549
}
@@ -552,8 +553,8 @@ void jBooleanArrayToCKBBoolArray(JNIEnv *env, const jbooleanArray jArray, CK_BBO
552553
return;
553554
}
554555

555-
*ckpArray = (CK_BBOOL*) calloc (*ckpLength, sizeof(CK_BBOOL));
556-
if (*ckpArray == NULL) {
556+
*ckpArray = (CK_BBOOL*) calloc(*ckpLength, sizeof(CK_BBOOL));
557+
if (*ckpArray == NULL && *ckpLength != 0UL) {
557558
free(jpTemp);
558559
p11ThrowOutOfMemoryError(env, 0);
559560
return;
@@ -577,13 +578,14 @@ void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *
577578
jbyte* jpTemp;
578579
CK_ULONG i;
579580

580-
*ckpLength = jArray == NULL ? 0L : (*env)->GetArrayLength(env, jArray);
581-
if(*ckpLength == 0L) {
581+
if (jArray == NULL) {
582582
*ckpArray = NULL_PTR;
583+
*ckpLength = 0UL;
583584
return;
584585
}
586+
*ckpLength = (*env)->GetArrayLength(env, jArray);
585587
jpTemp = (jbyte*) calloc(*ckpLength, sizeof(jbyte));
586-
if (jpTemp == NULL) {
588+
if (jpTemp == NULL && *ckpLength != 0UL) {
587589
p11ThrowOutOfMemoryError(env, 0);
588590
return;
589591
}
@@ -597,8 +599,8 @@ void jByteArrayToCKByteArray(JNIEnv *env, const jbyteArray jArray, CK_BYTE_PTR *
597599
if (sizeof(CK_BYTE) == sizeof(jbyte)) {
598600
*ckpArray = (CK_BYTE_PTR) jpTemp;
599601
} else {
600-
*ckpArray = (CK_BYTE_PTR) calloc (*ckpLength, sizeof(CK_BYTE));
601-
if (*ckpArray == NULL) {
602+
*ckpArray = (CK_BYTE_PTR) calloc(*ckpLength, sizeof(CK_BYTE));
603+
if (*ckpArray == NULL && *ckpLength != 0UL) {
602604
free(jpTemp);
603605
p11ThrowOutOfMemoryError(env, 0);
604606
return;
@@ -623,13 +625,14 @@ void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR
623625
jlong* jTemp;
624626
CK_ULONG i;
625627

626-
*ckpLength = jArray == NULL ? 0L : (*env)->GetArrayLength(env, jArray);
627-
if(*ckpLength == 0L) {
628+
if (jArray == NULL) {
628629
*ckpArray = NULL_PTR;
630+
*ckpLength = 0UL;
629631
return;
630632
}
633+
*ckpLength = (*env)->GetArrayLength(env, jArray);
631634
jTemp = (jlong*) calloc(*ckpLength, sizeof(jlong));
632-
if (jTemp == NULL) {
635+
if (jTemp == NULL && *ckpLength != 0UL) {
633636
p11ThrowOutOfMemoryError(env, 0);
634637
return;
635638
}
@@ -640,7 +643,7 @@ void jLongArrayToCKULongArray(JNIEnv *env, const jlongArray jArray, CK_ULONG_PTR
640643
}
641644

642645
*ckpArray = (CK_ULONG_PTR) calloc(*ckpLength, sizeof(CK_ULONG));
643-
if (*ckpArray == NULL) {
646+
if (*ckpArray == NULL && *ckpLength != 0UL) {
644647
free(jTemp);
645648
p11ThrowOutOfMemoryError(env, 0);
646649
return;
@@ -664,13 +667,14 @@ void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *
664667
jchar* jpTemp;
665668
CK_ULONG i;
666669

667-
*ckpLength = jArray == NULL ? 0L : (*env)->GetArrayLength(env, jArray);
668-
if(*ckpLength == 0L) {
670+
if (jArray == NULL) {
669671
*ckpArray = NULL_PTR;
672+
*ckpLength = 0UL;
670673
return;
671674
}
675+
*ckpLength = (*env)->GetArrayLength(env, jArray);
672676
jpTemp = (jchar*) calloc(*ckpLength, sizeof(jchar));
673-
if (jpTemp == NULL) {
677+
if (jpTemp == NULL && *ckpLength != 0UL) {
674678
p11ThrowOutOfMemoryError(env, 0);
675679
return;
676680
}
@@ -680,8 +684,8 @@ void jCharArrayToCKCharArray(JNIEnv *env, const jcharArray jArray, CK_CHAR_PTR *
680684
return;
681685
}
682686

683-
*ckpArray = (CK_CHAR_PTR) calloc (*ckpLength, sizeof(CK_CHAR));
684-
if (*ckpArray == NULL) {
687+
*ckpArray = (CK_CHAR_PTR) calloc(*ckpLength, sizeof(CK_CHAR));
688+
if (*ckpArray == NULL && *ckpLength != 0UL) {
685689
free(jpTemp);
686690
p11ThrowOutOfMemoryError(env, 0);
687691
return;
@@ -705,13 +709,14 @@ void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CH
705709
jchar* jTemp;
706710
CK_ULONG i;
707711

708-
*ckpLength = jArray == NULL ? 0L : (*env)->GetArrayLength(env, jArray);
709-
if(*ckpLength == 0L) {
712+
if (jArray == NULL) {
710713
*ckpArray = NULL_PTR;
714+
*ckpLength = 0UL;
711715
return;
712716
}
717+
*ckpLength = (*env)->GetArrayLength(env, jArray);
713718
jTemp = (jchar*) calloc(*ckpLength, sizeof(jchar));
714-
if (jTemp == NULL) {
719+
if (jTemp == NULL && *ckpLength != 0UL) {
715720
p11ThrowOutOfMemoryError(env, 0);
716721
return;
717722
}
@@ -721,7 +726,7 @@ void jCharArrayToCKUTF8CharArray(JNIEnv *env, const jcharArray jArray, CK_UTF8CH
721726
}
722727

723728
*ckpArray = (CK_UTF8CHAR_PTR) calloc(*ckpLength, sizeof(CK_UTF8CHAR));
724-
if (*ckpArray == NULL) {
729+
if (*ckpArray == NULL && *ckpLength != 0UL) {
725730
p11ThrowOutOfMemoryError(env, 0);
726731
goto cleanup;
727732
}
@@ -792,7 +797,7 @@ void jAttributeArrayToCKAttributeArray(JNIEnv *env, jobjectArray jArray, CK_ATTR
792797
jLength = (*env)->GetArrayLength(env, jArray);
793798
*ckpLength = jLongToCKULong(jLength);
794799
*ckpArray = (CK_ATTRIBUTE_PTR) calloc(*ckpLength, sizeof(CK_ATTRIBUTE));
795-
if (*ckpArray == NULL) {
800+
if (*ckpArray == NULL && *ckpLength != 0UL) {
796801
p11ThrowOutOfMemoryError(env, 0);
797802
return;
798803
}
@@ -833,7 +838,7 @@ jbyteArray ckByteArrayToJByteArray(JNIEnv *env, const CK_BYTE_PTR ckpArray, CK_U
833838
jpTemp = (jbyte*) ckpArray;
834839
} else {
835840
jpTemp = (jbyte*) calloc(ckLength, sizeof(jbyte));
836-
if (jpTemp == NULL) {
841+
if (jpTemp == NULL && ckLength != 0UL) {
837842
p11ThrowOutOfMemoryError(env, 0);
838843
return NULL;
839844
}
@@ -867,7 +872,7 @@ jlongArray ckULongArrayToJLongArray(JNIEnv *env, const CK_ULONG_PTR ckpArray, CK
867872
jlongArray jArray;
868873

869874
jpTemp = (jlong*) calloc(ckLength, sizeof(jlong));
870-
if (jpTemp == NULL) {
875+
if (jpTemp == NULL && ckLength != 0UL) {
871876
p11ThrowOutOfMemoryError(env, 0);
872877
return NULL;
873878
}
@@ -898,7 +903,7 @@ jcharArray ckCharArrayToJCharArray(JNIEnv *env, const CK_CHAR_PTR ckpArray, CK_U
898903
jcharArray jArray;
899904

900905
jpTemp = (jchar*) calloc(ckLength, sizeof(jchar));
901-
if (jpTemp == NULL) {
906+
if (jpTemp == NULL && ckLength != 0UL) {
902907
p11ThrowOutOfMemoryError(env, 0);
903908
return NULL;
904909
}
@@ -929,7 +934,7 @@ jcharArray ckUTF8CharArrayToJCharArray(JNIEnv *env, const CK_UTF8CHAR_PTR ckpArr
929934
jcharArray jArray;
930935

931936
jpTemp = (jchar*) calloc(ckLength, sizeof(jchar));
932-
if (jpTemp == NULL) {
937+
if (jpTemp == NULL && ckLength != 0UL) {
933938
p11ThrowOutOfMemoryError(env, 0);
934939
return NULL;
935940
}

‎test/jdk/ProblemList.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 gene
606606
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all
607607

608608
sun/security/tools/keytool/NssTest.java 8295343 linux-all
609-
sun/security/pkcs11/Signature/TestRSAKeyLength.java 8295343,8309569 linux-all,macosx-x64,windows-x64
609+
sun/security/pkcs11/Signature/TestRSAKeyLength.java 8295343 linux-all
610610
sun/security/pkcs11/rsa/TestSignatures.java 8295343 linux-all
611611
sun/security/pkcs11/rsa/TestKeyPairGenerator.java 8295343 linux-all
612612
sun/security/pkcs11/rsa/TestKeyFactory.java 8295343 linux-all

0 commit comments

Comments
 (0)
Please sign in to comment.