提交 ab86581a 编写于 作者: M mullan

8234418: Better parsing with CertificateFactory

Reviewed-by: weijun, mschoene, rhalade
上级 fc28d3fd
...@@ -354,8 +354,12 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ...@@ -354,8 +354,12 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
second += toDigit(buf[pos++], type); second += toDigit(buf[pos++], type);
len -= 2; len -= 2;
// handle fractional seconds (if present) // handle fractional seconds (if present)
if (buf[pos] == '.' || buf[pos] == ',') { if (generalized && (buf[pos] == '.' || buf[pos] == ',')) {
len --; len --;
if (len == 0) {
throw new IOException("Parse " + type +
" time, empty fractional part");
}
pos++; pos++;
int precision = 0; int precision = 0;
while (buf[pos] != 'Z' && while (buf[pos] != 'Z' &&
...@@ -365,6 +369,11 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ...@@ -365,6 +369,11 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
// store millisecond precision only // store millisecond precision only
int thisDigit = toDigit(buf[pos], type); int thisDigit = toDigit(buf[pos], type);
precision++; precision++;
len--;
if (len == 0) {
throw new IOException("Parse " + type +
" time, invalid fractional part");
}
pos++; pos++;
switch (precision) { switch (precision) {
case 1: case 1:
...@@ -382,7 +391,6 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ...@@ -382,7 +391,6 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
throw new IOException("Parse " + type + throw new IOException("Parse " + type +
" time, empty fractional part"); " time, empty fractional part");
} }
len -= precision;
} }
} else } else
second = 0; second = 0;
...@@ -412,6 +420,9 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ...@@ -412,6 +420,9 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
switch (buf[pos++]) { switch (buf[pos++]) {
case '+': case '+':
if (len != 5) {
throw new IOException("Parse " + type + " time, invalid offset");
}
hr = 10 * toDigit(buf[pos++], type); hr = 10 * toDigit(buf[pos++], type);
hr += toDigit(buf[pos++], type); hr += toDigit(buf[pos++], type);
min = 10 * toDigit(buf[pos++], type); min = 10 * toDigit(buf[pos++], type);
...@@ -424,6 +435,9 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ...@@ -424,6 +435,9 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
break; break;
case '-': case '-':
if (len != 5) {
throw new IOException("Parse " + type + " time, invalid offset");
}
hr = 10 * toDigit(buf[pos++], type); hr = 10 * toDigit(buf[pos++], type);
hr += toDigit(buf[pos++], type); hr += toDigit(buf[pos++], type);
min = 10 * toDigit(buf[pos++], type); min = 10 * toDigit(buf[pos++], type);
...@@ -436,6 +450,9 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable { ...@@ -436,6 +450,9 @@ class DerInputBuffer extends ByteArrayInputStream implements Cloneable {
break; break;
case 'Z': case 'Z':
if (len != 1) {
throw new IOException("Parse " + type + " time, invalid format");
}
break; break;
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册