diff options
| -rw-r--r-- | talpid-core/src/dns/windows/tcpip.rs | 8 | ||||
| -rw-r--r-- | talpid-openvpn/src/wintun.rs | 7 | ||||
| -rw-r--r-- | talpid-windows/src/net.rs | 4 |
3 files changed, 12 insertions, 7 deletions
diff --git a/talpid-core/src/dns/windows/tcpip.rs b/talpid-core/src/dns/windows/tcpip.rs index 70bb4660d6..3e0a8ea6e1 100644 --- a/talpid-core/src/dns/windows/tcpip.rs +++ b/talpid-core/src/dns/windows/tcpip.rs @@ -164,8 +164,12 @@ fn flush_dns_cache() -> Result<(), Error> { /// Obtain a string representation for a GUID object. fn string_from_guid(guid: &GUID) -> String { let mut buffer = [0u16; 40]; - let length = unsafe { StringFromGUID2(guid, &mut buffer[0] as *mut _, buffer.len() as i32 - 1) } - as usize; + + let length = + // SAFETY: `guid` and `buffer` are valid references. + // StringFromGUID2 won't write past the end of the provided length. + unsafe { StringFromGUID2(guid, buffer.as_mut_ptr(), buffer.len() as i32 - 1) } as usize; + // cannot fail because `buffer` is large enough assert!(length > 0); let length = length - 1; diff --git a/talpid-openvpn/src/wintun.rs b/talpid-openvpn/src/wintun.rs index 21c81e0161..ef5ebd5482 100644 --- a/talpid-openvpn/src/wintun.rs +++ b/talpid-openvpn/src/wintun.rs @@ -349,8 +349,11 @@ fn find_adapter_registry_key(find_guid: &str, permissions: REG_SAM_FLAGS) -> io: /// Obtain a string representation for a GUID object. fn string_from_guid(guid: &GUID) -> String { let mut buffer = [0u16; 40]; - let length = unsafe { StringFromGUID2(guid, &mut buffer[0] as *mut _, buffer.len() as i32 - 1) } - as usize; + + // SAFETY: `guid` and `buffer` are valid references. + let length = + unsafe { StringFromGUID2(guid, buffer.as_mut_ptr(), buffer.len() as i32 - 1) } as usize; + // cannot fail because `buffer` is large enough assert!(length > 0); let length = length - 1; diff --git a/talpid-windows/src/net.rs b/talpid-windows/src/net.rs index a15a2a82db..33c79e1a9d 100644 --- a/talpid-windows/src/net.rs +++ b/talpid-windows/src/net.rs @@ -393,9 +393,7 @@ pub fn luid_from_alias<T: AsRef<OsStr>>(alias: T) -> io::Result<NET_LUID_LH> { /// Returns the alias of an interface given its LUID. pub fn alias_from_luid(luid: &NET_LUID_LH) -> io::Result<OsString> { let mut buffer = [0u16; IF_MAX_STRING_SIZE as usize + 1]; - win32_err!(unsafe { - ConvertInterfaceLuidToAlias(luid, &mut buffer[0] as *mut _, buffer.len()) - })?; + win32_err!(unsafe { ConvertInterfaceLuidToAlias(luid, buffer.as_mut_ptr(), buffer.len()) })?; let nul = buffer.iter().position(|&c| c == 0u16).unwrap(); Ok(OsString::from_wide(&buffer[0..nul])) } |
