Skip to content

Commit 8c0d026

Browse files
Mark PowersValerie Peng
authored andcommitted
8315042: NPE in PKCS7.parseOldSignedData
Reviewed-by: valeriep, weijun
1 parent f7deaf4 commit 8c0d026

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

src/java.base/share/classes/sun/security/pkcs/PKCS7.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ private void parse(DerInputStream derin, boolean oldStyle)
152152
ObjectIdentifier contentType = block.contentType;
153153
DerValue content = block.getContent();
154154

155+
if (content == null) {
156+
throw new ParsingException("content is null");
157+
}
158+
155159
if (contentType.equals(ContentInfo.SIGNED_DATA_OID)) {
156160
parseSignedData(content);
157161
} else if (contentType.equals(ContentInfo.OLD_SIGNED_DATA_OID)) {
Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,56 +23,43 @@
2323

2424
/*
2525
* @test
26-
* @bug 5052433
27-
* @summary NullPointerException for generateCRL and generateCRLs methods.
26+
* @bug 5052433 8315042
27+
* @summary Verify that generateCRL and generateCRLs methods do not throw
28+
* NullPointerException. They should throw CRLException instead.
29+
* @library /test/lib
2830
*/
2931
import java.security.NoSuchProviderException;
3032
import java.security.cert.*;
3133
import java.io.ByteArrayInputStream;
34+
import java.util.Base64;
3235

33-
public class UnexpectedNPE {
34-
CertificateFactory cf = null ;
36+
import jdk.test.lib.Utils;
3537

36-
public UnexpectedNPE() {}
38+
public class UnexpectedNPE {
39+
static CertificateFactory cf = null;
3740

38-
public static void main( String[] av ) {
41+
public static void main(String[] av ) throws CertificateException,
42+
NoSuchProviderException {
3943
byte[] encoded_1 = { 0x00, 0x00, 0x00, 0x00 };
4044
byte[] encoded_2 = { 0x30, 0x01, 0x00, 0x00 };
4145
byte[] encoded_3 = { 0x30, 0x01, 0x00 };
46+
byte[] encoded_4 = Base64.getDecoder().decode(
47+
"MAsGCSqGSMP7TQEHAjI1Bgn///////8wCwUyAQ==");
4248

43-
UnexpectedNPE unpe = new UnexpectedNPE() ;
44-
45-
if(!unpe.run(encoded_1)) {
46-
throw new SecurityException("CRLException has not been thrown");
47-
}
49+
cf = CertificateFactory.getInstance("X.509", "SUN");
4850

49-
if(!unpe.run(encoded_2)) {
50-
throw new SecurityException("CRLException has not been thrown");
51-
}
52-
53-
if(!unpe.run(encoded_2)) {
54-
throw new SecurityException("CRLException has not been thrown");
55-
}
51+
run(encoded_1);
52+
run(encoded_2);
53+
run(encoded_3);
54+
run(encoded_4);
5655
}
5756

58-
private boolean run(byte[] buf) {
59-
if (cf == null) {
60-
try {
61-
cf = CertificateFactory.getInstance("X.509", "SUN");
62-
} catch (CertificateException e) {
63-
throw new SecurityException("Cannot get CertificateFactory");
64-
} catch (NoSuchProviderException npe) {
65-
throw new SecurityException("Cannot get CertificateFactory");
66-
}
67-
}
68-
try {
69-
cf.generateCRL(new ByteArrayInputStream(buf));
70-
} catch (CRLException ce) {
71-
System.out.println("NPE checking passed");
72-
return true;
73-
}
74-
75-
System.out.println("CRLException has not been thrown");
76-
return false;
57+
private static void run(byte[] buf) {
58+
Utils.runAndCheckException(
59+
() -> cf.generateCRL(new ByteArrayInputStream(buf)),
60+
CRLException.class);
61+
Utils.runAndCheckException(
62+
() -> cf.generateCRLs(new ByteArrayInputStream(buf)),
63+
CRLException.class);
7764
}
7865
}

0 commit comments

Comments
 (0)