8222751: closed/test/jdk/sun/security/util/DerIndefLenConverter/IndefBerPkcs12.java fail

Reviewed-by: jnimeh, ascarpino, ssahoo, skoivu
This commit is contained in:
Weijun Wang 2019-04-23 08:34:51 +08:00
parent bac946663d
commit cd020a13c9
2 changed files with 34 additions and 34 deletions

View file

@ -92,43 +92,37 @@ class DerIndefLenConverter {
* add the current position to the <code>eocList</code> vector. * add the current position to the <code>eocList</code> vector.
*/ */
private void parseTag() throws IOException { private void parseTag() throws IOException {
if (dataPos == dataSize) if (isEOC(data[dataPos]) && (data[dataPos + 1] == 0)) {
return; int numOfEncapsulatedLenBytes = 0;
try { Object elem = null;
if (isEOC(data[dataPos]) && (data[dataPos + 1] == 0)) { int index;
int numOfEncapsulatedLenBytes = 0; for (index = ndefsList.size()-1; index >= 0; index--) {
Object elem = null; // Determine the first element in the vector that does not
int index; // have a matching EOC
for (index = ndefsList.size()-1; index >= 0; index--) { elem = ndefsList.get(index);
// Determine the first element in the vector that does not if (elem instanceof Integer) {
// have a matching EOC break;
elem = ndefsList.get(index); } else {
if (elem instanceof Integer) { numOfEncapsulatedLenBytes += ((byte[])elem).length - 3;
break;
} else {
numOfEncapsulatedLenBytes += ((byte[])elem).length - 3;
}
} }
if (index < 0) {
throw new IOException("EOC does not have matching " +
"indefinite-length tag");
}
int sectionLen = dataPos - ((Integer)elem).intValue() +
numOfEncapsulatedLenBytes;
byte[] sectionLenBytes = getLengthBytes(sectionLen);
ndefsList.set(index, sectionLenBytes);
unresolved--;
// Add the number of bytes required to represent this section
// to the total number of length bytes,
// and subtract the indefinite-length tag (1 byte) and
// EOC bytes (2 bytes) for this section
numOfTotalLenBytes += (sectionLenBytes.length - 3);
} }
dataPos++; if (index < 0) {
} catch (IndexOutOfBoundsException iobe) { throw new IOException("EOC does not have matching " +
throw new IOException(iobe); "indefinite-length tag");
}
int sectionLen = dataPos - ((Integer)elem).intValue() +
numOfEncapsulatedLenBytes;
byte[] sectionLenBytes = getLengthBytes(sectionLen);
ndefsList.set(index, sectionLenBytes);
unresolved--;
// Add the number of bytes required to represent this section
// to the total number of length bytes,
// and subtract the indefinite-length tag (1 byte) and
// EOC bytes (2 bytes) for this section
numOfTotalLenBytes += (sectionLenBytes.length - 3);
} }
dataPos++;
} }
/** /**
@ -336,6 +330,10 @@ class DerIndefLenConverter {
// parse and set up the vectors of all the indefinite-lengths // parse and set up the vectors of all the indefinite-lengths
while (dataPos < dataSize) { while (dataPos < dataSize) {
if (dataPos + 2 > dataSize) {
// There should be at least one tag and one length
return null;
}
parseTag(); parseTag();
len = parseLength(); len = parseLength();
if (len < 0) { if (len < 0) {

View file

@ -269,6 +269,8 @@ public class KeyStoreDelegator extends KeyStoreSpi {
throw (CertificateException)e; throw (CertificateException)e;
} else if (e instanceof NoSuchAlgorithmException) { } else if (e instanceof NoSuchAlgorithmException) {
throw (NoSuchAlgorithmException)e; throw (NoSuchAlgorithmException)e;
} else if (e instanceof RuntimeException){
throw (RuntimeException)e;
} }
} }
} }