diff --git a/Cargo.toml b/Cargo.toml index 2fc555a..7719864 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ keywords = ["password", "credential", "keychain", "keyring", "cross-platform"] license = "MIT OR Apache-2.0" name = "keyring" repository = "https://github.com/hwchen/keyring-rs.git" -version = "2.3.2" +version = "2.3.3" rust-version = "1.68" edition = "2021" exclude = [".github/"] diff --git a/src/keyutils.rs b/src/keyutils.rs index 21681bd..d7a5245 100644 --- a/src/keyutils.rs +++ b/src/keyutils.rs @@ -241,7 +241,7 @@ impl KeyutilsCredential { // Construct the credential with a URI-style description let description = match target { - Some(value) if value.is_empty() => { + Some("") => { return Err(ErrorCode::Invalid( "target".to_string(), "cannot be empty".to_string(), diff --git a/src/windows.rs b/src/windows.rs index aa505e4..99efca7 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -326,6 +326,9 @@ fn extract_password(credential: &CREDENTIALW) -> Result { // get password blob let blob_pointer: *const u8 = credential.CredentialBlob; let blob_len: usize = credential.CredentialBlobSize as usize; + if blob_len == 0 { + return Ok(String::new()); + } let blob = unsafe { std::slice::from_raw_parts(blob_pointer, blob_len) }; // 3rd parties may write credential data with an odd number of bytes, // so we make sure that we don't try to decode those as utf16 @@ -355,6 +358,9 @@ unsafe fn from_wstr(ws: *const u16) -> String { } // this code from https://stackoverflow.com/a/48587463/558006 let len = (0..).take_while(|&i| *ws.offset(i) != 0).count(); + if len == 0 { + return String::new(); + } let slice = std::slice::from_raw_parts(ws, len); String::from_utf16_lossy(slice) }