Skip to content

Commit

Permalink
openpgp: prevent panic for missing self-signature
Browse files Browse the repository at this point in the history
There can be public keys where an identity has no self-signature. Since
the order of identities as tested against `shouldPreferIdentity` is
unstable (due to being based on a map iteration), such a situation leads
to a panic in a certain percentage of runs.

Avoid the panic by preferring the potential new identity. This can still
lead to unusable results, but they will returned as a proper error,
allowing an application to handle it.
  • Loading branch information
bitfehler committed Mar 29, 2022
1 parent 70ae35b commit c0ca1df
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions openpgp/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func shouldPreferIdentity(existingId, potentialNewId *Identity) bool {
return false
}

if existingId.SelfSignature == nil {
return true
}

if (existingId.SelfSignature.IsPrimaryId != nil && *existingId.SelfSignature.IsPrimaryId &&
!(potentialNewId.SelfSignature.IsPrimaryId != nil && *potentialNewId.SelfSignature.IsPrimaryId)) {
return false
Expand Down

0 comments on commit c0ca1df

Please sign in to comment.