diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-07-28 14:56:25 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-07-28 14:56:25 +0200 |
commit | c54ccf9d80a3e4e55474324bff9b116b66153e2f (patch) | |
tree | 700bb5804a7a9f9080cf9f739d712732ffb4a4b8 /openpgp/src/packet/pkesk.rs | |
parent | 992b394d3627f866b39f39c35c42d512c409beeb (diff) |
openpgp: Fix subtraction with overflow.
- When the decryptor returns a short session key without reporting
an error, an overflow occurs. Avoid this by using saturating
subtraction. Then, the resulting range is empty, and an error
will be reported just a few lines down.
- Fixes #913.
Diffstat (limited to 'openpgp/src/packet/pkesk.rs')
-rw-r--r-- | openpgp/src/packet/pkesk.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index bf4464f9..ac0b7932 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -155,7 +155,7 @@ impl PKESK3 { None }; let plain = decryptor.decrypt(&self.esk, plaintext_len)?; - let key_rgn = 1..(plain.len() - 2); + let key_rgn = 1..plain.len().saturating_sub(2); let sym_algo: SymmetricAlgorithm = plain[0].into(); let mut key: SessionKey = vec![0u8; sym_algo.key_size()?].into(); |