Merge pull request #212 from gsora/fix/payloadtype-oob-read

fix(vault): don't panic when reading backup::PayloadType off an empty vec
This commit is contained in:
bunnie 2022-08-13 22:23:07 +08:00 committed by GitHub
commit 68902600c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -334,12 +334,16 @@ impl From<&PayloadType> for u8 {
#[derive(Debug)]
pub enum PayloadTypeError {
BadType
BadType,
}
impl TryFrom<&Vec<u8>> for PayloadType {
type Error = PayloadTypeError;
fn try_from(u: &Vec<u8>) -> Result<PayloadType, Self::Error> {
if u.is_empty() {
return Err(PayloadTypeError::BadType);
}
match u[0] {
1 => Ok(PayloadType::TOTP),
2 => Ok(PayloadType::Password),