summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorJoakim Hulthe <joakim.hulthe@mullvad.net>2025-02-13 18:39:52 +0100
committerJoakim Hulthe <joakim.hulthe@mullvad.net>2025-02-25 13:43:53 +0100
commitb899e4b0cda73cca24dc22c8396d72b1cc39dc6c (patch)
treeac54e67c63c404f7d30829cc08c332e7ab1fe21c /talpid-core/src
parent0cce552a63620ca316a21ee29abcb9f0ab23cf52 (diff)
downloadmullvadvpn-b899e4b0cda73cca24dc22c8396d72b1cc39dc6c.tar.xz
mullvadvpn-b899e4b0cda73cca24dc22c8396d72b1cc39dc6c.zip
Fix improper pointer provenance
`&mut buffer[0] as *mut u8` will create a raw pointer that is only allowed to access the very first byte of `buffer`. `slice::as_mut_ptr` is preferred.
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/dns/windows/tcpip.rs8
1 files changed, 6 insertions, 2 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;