Skip to content

Commit 8ac04d1

Browse files
committed
Check for nul in Windows utf-16 wide-string.
1 parent cc6df1d commit 8ac04d1

File tree

1 file changed

+7
-1
lines changed
  • crates/credential/cargo-credential-wincred/src

1 file changed

+7
-1
lines changed

crates/credential/cargo-credential-wincred/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ use winapi::um::winnt::LPWSTR;
1010

1111
struct WindowsCredential;
1212

13+
/// Converts a string to a nul-terminated wide UTF-16 byte sequence.
1314
fn wstr(s: &str) -> Vec<u16> {
14-
OsStr::new(s).encode_wide().chain(Some(0)).collect()
15+
let mut wide: Vec<u16> = OsStr::new(s).encode_wide().collect();
16+
if wide.iter().any(|b| *b == 0) {
17+
panic!("nul byte in wide string");
18+
}
19+
wide.push(0);
20+
wide
1521
}
1622

1723
fn target_name(registry_name: &str) -> Vec<u16> {

0 commit comments

Comments
 (0)