mirror of
https://github.com/torproject/metrics-lib.git
synced 2024-11-26 18:50:28 +00:00
Fix NPE when parsing invalid crypto blocks.
This commit is contained in:
parent
a8e0cb7ab7
commit
d6e9a0d75e
@ -1,5 +1,9 @@
|
||||
# Changes in version 2.?.? - 2019-1?-??
|
||||
|
||||
* Minor changes
|
||||
- Fix a NullPointerException when parsing an invalid crypto block
|
||||
starting with "-----END " rather than "-----BEGIN ".
|
||||
|
||||
|
||||
# Changes in version 2.9.1 - 2019-11-09
|
||||
|
||||
|
@ -80,6 +80,10 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
|
@ -70,6 +70,10 @@ public class DirectorySignatureImpl implements DirectorySignature {
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
|
@ -242,6 +242,10 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
|
||||
cryptoLines.add(line);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == cryptoLines) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
cryptoLines.add(line);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String cryptoLine : cryptoLines) {
|
||||
|
@ -71,6 +71,10 @@ public class MicrodescriptorImpl extends DescriptorImpl
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
|
@ -125,6 +125,10 @@ public class RelayDirectoryImpl extends DescriptorImpl
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
@ -215,6 +219,10 @@ public class RelayDirectoryImpl extends DescriptorImpl
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
|
@ -81,6 +81,10 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
@ -130,6 +134,10 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
|
@ -186,6 +186,10 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
|
||||
crypto.append(line).append(NL);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == crypto) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
crypto.append(line).append(NL);
|
||||
String cryptoString = crypto.toString();
|
||||
crypto = null;
|
||||
|
@ -181,6 +181,10 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
|
||||
cryptoLines.add(line);
|
||||
break;
|
||||
case CRYPTO_END:
|
||||
if (null == cryptoLines) {
|
||||
throw new DescriptorParseException(Key.CRYPTO_END + " before "
|
||||
+ Key.CRYPTO_BEGIN);
|
||||
}
|
||||
cryptoLines.add(line);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String cryptoLine : cryptoLines) {
|
||||
|
@ -2243,6 +2243,16 @@ public class ExtraInfoDescriptorImplTest {
|
||||
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEd25519IdentityInvalidCrypto()
|
||||
throws DescriptorParseException {
|
||||
this.thrown.expect(DescriptorParseException.class);
|
||||
this.thrown.expectMessage("CRYPTO_END before CRYPTO_BEGIN");
|
||||
DescriptorBuilder.createWithEd25519Lines("identity-ed25519\n"
|
||||
+ "-----END ED25519 CERT-----\n-----BEGIN ED25519 CERT-----",
|
||||
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEd25519MasterKeyMissing()
|
||||
throws DescriptorParseException {
|
||||
|
@ -1825,6 +1825,16 @@ public class ServerDescriptorImplTest {
|
||||
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEd25519IdentityInvalidCrypto()
|
||||
throws DescriptorParseException {
|
||||
this.thrown.expect(DescriptorParseException.class);
|
||||
this.thrown.expectMessage("CRYPTO_END before CRYPTO_BEGIN");
|
||||
DescriptorBuilder.createWithEd25519Lines("identity-ed25519\n"
|
||||
+ "-----END ED25519 CERT-----\n-----BEGIN ED25519 CERT-----",
|
||||
MASTER_KEY_ED25519_LINE, ROUTER_SIG_ED25519_LINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEd25519MasterKeyMissing()
|
||||
throws DescriptorParseException {
|
||||
|
Loading…
Reference in New Issue
Block a user