diff options
author | Neal H. Walfield <neal@pep.foundation> | 2018-11-26 22:57:06 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2018-11-26 23:09:59 +0100 |
commit | b46228287cacf4159e95abe792ce0ae82c81ffaa (patch) | |
tree | d64c1612173c3152ff04041f39018c0f7de2fcd4 /ffi | |
parent | bc956960983da8929b8392cbec25ffbc86b8883e (diff) |
ffi: Avoid NULL pointer dereference.
- The callback can fail to return the secret. Fail gracefully.
Diffstat (limited to 'ffi')
-rw-r--r-- | ffi/src/error.rs | 6 | ||||
-rw-r--r-- | ffi/src/openpgp.rs | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/ffi/src/error.rs b/ffi/src/error.rs index 75fa4f3e..96a64c96 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -86,6 +86,9 @@ pub enum Status { /// Invalid session key. InvalidSessionKey = -12, + /// Missing session key. + MissingSessionKey = -27, + /// Malformed TPK. MalformedTPK = -13, @@ -119,6 +122,7 @@ pub enum Status { // XXX: Skipping ManipulatedMessage = -25 // XXX: Skipping UnsupportedAEADAlgorithm = -26 + // XXX: Skipping MissingSessionKey = -27 } impl<'a> From<&'a failure::Error> for Status { @@ -156,6 +160,8 @@ impl<'a> From<&'a failure::Error> for Status { Status::InvalidPassword, &openpgp::Error::InvalidSessionKey(_) => Status::InvalidSessionKey, + &openpgp::Error::MissingSessionKey(_) => + Status::MissingSessionKey, &openpgp::Error::MalformedMPI(_) => Status::MalformedMPI, &openpgp::Error::BadSignature(_) => diff --git a/ffi/src/openpgp.rs b/ffi/src/openpgp.rs index d772f2ef..cd158d85 100644 --- a/ffi/src/openpgp.rs +++ b/ffi/src/openpgp.rs @@ -2517,6 +2517,11 @@ impl DecryptionHelper for DHelper { format!("{:?}", result)).into()); } + if secret.is_null() { + return Err(openpgp::Error::MissingSessionKey( + "Callback did not return a session key".into()).into()); + } + let secret = unsafe { Box::from_raw(secret) }; |