From 669fbb40d894460e9603dcf6e953373e53a19347 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 28 Jan 2020 19:42:41 +0100 Subject: Use CString to store temporary passwords This patch changes the generate_password function and the User and Admin structs to use a CString instead of a Vec when storing temporary passwords. This makes sure that the strings that are passed to the C API are properly null-terminated. --- src/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/util.rs') diff --git a/src/util.rs b/src/util.rs index 5a56c55..b9b1a68 100644 --- a/src/util.rs +++ b/src/util.rs @@ -75,10 +75,10 @@ pub fn get_last_error() -> Error { } } -pub fn generate_password(length: usize) -> Result, Error> { +pub fn generate_password(length: usize) -> Result { let mut data = vec![0u8; length]; OsRng.fill_bytes(&mut data[..]); - Ok(data) + get_cstring(data) } pub fn get_cstring>>(s: T) -> Result { -- cgit v1.2.1