watch out for nullpointers from get(Un|)HashedSubpackets

fixes #721
This commit is contained in:
Vincent Breitmoser 2014-07-28 17:04:25 +02:00
parent cce243299a
commit da131220aa
3 changed files with 19 additions and 10 deletions

View File

@ -413,7 +413,8 @@ public class PgpKeyOperation {
} }
// if this is~ the/a primary user id // if this is~ the/a primary user id
if (currentCert.hasSubpackets() && currentCert.getHashedSubPackets().isPrimaryUserID()) { if (currentCert.getHashedSubPackets() != null
&& currentCert.getHashedSubPackets().isPrimaryUserID()) {
// if it's the one we want, just leave it as is // if it's the one we want, just leave it as is
if (userId.equals(saveParcel.mChangePrimaryUserId)) { if (userId.equals(saveParcel.mChangePrimaryUserId)) {
ok = true; ok = true;
@ -740,7 +741,7 @@ public class PgpKeyOperation {
int flags = 0; int flags = 0;
//noinspection unchecked //noinspection unchecked
for(PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) { for(PGPSignature sig : new IterableIterator<PGPSignature>(key.getSignatures())) {
if (!sig.hasSubpackets()) { if (sig.getHashedSubPackets() == null) {
continue; continue;
} }
flags |= sig.getHashedSubPackets().getKeyFlags(); flags |= sig.getHashedSubPackets().getKeyFlags();

View File

@ -513,7 +513,8 @@ public class UncachedKeyRing {
} }
// if this certificate says it allows signing for the key // if this certificate says it allows signing for the key
if (zert.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.KEY_FLAGS)) { if (zert.getHashedSubPackets() != null &&
zert.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.KEY_FLAGS)) {
int flags = ((KeyFlags) zert.getHashedSubPackets() int flags = ((KeyFlags) zert.getHashedSubPackets()
.getSubpacket(SignatureSubpacketTags.KEY_FLAGS)).getFlags(); .getSubpacket(SignatureSubpacketTags.KEY_FLAGS)).getFlags();

View File

@ -63,14 +63,18 @@ public class WrappedSignature {
} }
try { try {
PGPSignatureList list; PGPSignatureList list;
if (mSig.getHashedSubPackets() != null) {
list = mSig.getHashedSubPackets().getEmbeddedSignatures(); list = mSig.getHashedSubPackets().getEmbeddedSignatures();
for(int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
sigs.add(new WrappedSignature(list.get(i))); sigs.add(new WrappedSignature(list.get(i)));
} }
}
if (mSig.getUnhashedSubPackets() != null) {
list = mSig.getUnhashedSubPackets().getEmbeddedSignatures(); list = mSig.getUnhashedSubPackets().getEmbeddedSignatures();
for(int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
sigs.add(new WrappedSignature(list.get(i))); sigs.add(new WrappedSignature(list.get(i)));
} }
}
} catch (PGPException e) { } catch (PGPException e) {
// no matter // no matter
Log.e(Constants.TAG, "exception reading embedded signatures", e); Log.e(Constants.TAG, "exception reading embedded signatures", e);
@ -97,6 +101,9 @@ public class WrappedSignature {
if(!isRevocation()) { if(!isRevocation()) {
throw new PgpGeneralException("Not a revocation signature."); throw new PgpGeneralException("Not a revocation signature.");
} }
if (mSig.getHashedSubPackets() == null) {
return null;
}
SignatureSubpacket p = mSig.getHashedSubPackets().getSubpacket( SignatureSubpacket p = mSig.getHashedSubPackets().getSubpacket(
SignatureSubpacketTags.REVOCATION_REASON); SignatureSubpacketTags.REVOCATION_REASON);
// For some reason, this is missing in SignatureSubpacketInputStream:146 // For some reason, this is missing in SignatureSubpacketInputStream:146
@ -205,7 +212,7 @@ public class WrappedSignature {
} }
public boolean isLocal() { public boolean isLocal() {
if (!mSig.hasSubpackets() if (mSig.getHashedSubPackets() == null
|| !mSig.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.EXPORTABLE)) { || !mSig.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.EXPORTABLE)) {
return false; return false;
} }