summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2025-11-20 16:09:15 +0100
committerLinus Färnstrand <linus@mullvad.net>2025-11-21 11:14:31 +0100
commita9a7e6c8294c152b8fecf8b76b14595aaf37bdc8 (patch)
treeb3aa41a0f655be5f3dfea42ee70e369c6091b75c
parent246c6e8b4ba4ebbfdade510c86bb3a3796c6e723 (diff)
downloadmullvadvpn-a9a7e6c8294c152b8fecf8b76b14595aaf37bdc8.tar.xz
mullvadvpn-a9a7e6c8294c152b8fecf8b76b14595aaf37bdc8.zip
Replace `as _` casts with safer alternatives on Windows
-rw-r--r--installer-downloader/src/winapi_impl/ui.rs2
-rw-r--r--mullvad-paths/src/windows.rs22
-rw-r--r--talpid-windows/src/fs.rs6
-rw-r--r--windows-installer/src/windows.rs4
4 files changed, 21 insertions, 13 deletions
diff --git a/installer-downloader/src/winapi_impl/ui.rs b/installer-downloader/src/winapi_impl/ui.rs
index bb6a3398d0..8d6fe7dcc4 100644
--- a/installer-downloader/src/winapi_impl/ui.rs
+++ b/installer-downloader/src/winapi_impl/ui.rs
@@ -412,7 +412,7 @@ fn handle_link_messages(
if msg == WM_CTLCOLORSTATIC && Some(p) == link_hwnd {
// SAFETY: `w` is a valid device context for WM_CTLCOLORSTATIC
unsafe {
- SetBkMode(w as HDC, TRANSPARENT as _);
+ SetBkMode(w as HDC, TRANSPARENT as i32);
SetTextColor(w as HDC, rgb(LINK_COLOR));
}
// Out of bounds background
diff --git a/mullvad-paths/src/windows.rs b/mullvad-paths/src/windows.rs
index dd46e1af3e..48ca700522 100644
--- a/mullvad-paths/src/windows.rs
+++ b/mullvad-paths/src/windows.rs
@@ -1,6 +1,7 @@
use crate::{Error, Result, UserPermissions};
use once_cell::sync::OnceCell;
use std::{
+ ffi::c_void,
io, mem,
os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, OwnedHandle},
path::{Path, PathBuf},
@@ -161,7 +162,7 @@ fn set_security_permissions(path: &Path, user_permissions: UserPermissions) -> R
CreateWellKnownSid(
WinBuiltinAdministratorsSid,
ptr::null_mut(),
- admin_psid.as_mut_ptr() as _,
+ admin_psid.as_mut_ptr().cast::<c_void>(),
&raw mut admin_psid_len,
)
} == 0
@@ -195,7 +196,7 @@ fn set_security_permissions(path: &Path, user_permissions: UserPermissions) -> R
CreateWellKnownSid(
WinAuthenticatedUserSid,
ptr::null_mut(),
- au_psid.as_mut_ptr() as _,
+ au_psid.as_mut_ptr().cast::<c_void>(),
&raw mut au_psid_len,
)
} == 0
@@ -211,7 +212,7 @@ fn set_security_permissions(path: &Path, user_permissions: UserPermissions) -> R
MultipleTrusteeOperation: NO_MULTIPLE_TRUSTEE,
TrusteeForm: TRUSTEE_IS_SID,
TrusteeType: TRUSTEE_IS_GROUP,
- ptstrName: au_psid.as_mut_ptr() as *mut _,
+ ptstrName: au_psid.as_mut_ptr().cast(),
};
let authenticated_users_ea = EXPLICIT_ACCESS_W {
@@ -250,8 +251,8 @@ fn set_security_permissions(path: &Path, user_permissions: UserPermissions) -> R
wide_path.as_ptr(),
SE_FILE_OBJECT,
security_information,
- admin_psid.as_mut_ptr() as *mut _,
- admin_psid.as_mut_ptr() as *mut _,
+ admin_psid.as_mut_ptr().cast(),
+ admin_psid.as_mut_ptr().cast(),
new_dacl,
ptr::null(),
)
@@ -530,7 +531,7 @@ fn is_local_system_user_token(token: &impl AsRawHandle) -> io::Result<bool> {
GetTokenInformation(
token.as_raw_handle(),
TokenUser,
- token_info.as_mut_ptr() as _,
+ token_info.as_mut_ptr().cast::<c_void>(),
u32::try_from(token_info.len()).expect("len must fit in u32"),
&raw mut returned_info_len,
)
@@ -564,7 +565,7 @@ fn is_local_system_user_token(token: &impl AsRawHandle) -> io::Result<bool> {
CreateWellKnownSid(
WinLocalSystemSid,
std::ptr::null_mut(),
- local_system_sid.as_mut_ptr() as _,
+ local_system_sid.as_mut_ptr().cast::<c_void>(),
&raw mut local_system_size,
)
} == 0
@@ -575,5 +576,10 @@ fn is_local_system_user_token(token: &impl AsRawHandle) -> io::Result<bool> {
}
// SAFETY: Both arguments point to valid security identifiers
- Ok(unsafe { EqualSid(token_user.User.Sid, local_system_sid.as_ptr() as _) } != 0)
+ Ok(unsafe {
+ EqualSid(
+ token_user.User.Sid,
+ local_system_sid.as_mut_ptr().cast::<c_void>(),
+ )
+ } != 0)
}
diff --git a/talpid-windows/src/fs.rs b/talpid-windows/src/fs.rs
index 7e8e968bcc..240d2eae02 100644
--- a/talpid-windows/src/fs.rs
+++ b/talpid-windows/src/fs.rs
@@ -1,3 +1,4 @@
+use std::ffi::c_void;
use std::io;
use std::os::windows::io::AsRawHandle;
use std::ptr;
@@ -35,9 +36,10 @@ pub fn is_admin_owned<T: AsRawHandle>(handle: T) -> io::Result<bool> {
}
// SAFETY: `owner` is valid since `security_descriptor` still is, and the well-known type is a valid argument
- let is_system_owned = unsafe { IsWellKnownSid(owner as _, WinLocalSystemSid) != 0 };
+ let is_system_owned = unsafe { IsWellKnownSid(owner.cast::<c_void>(), WinLocalSystemSid) != 0 };
// SAFETY: `owner` is valid since `security_descriptor` still is, and the well-known type is a valid argument
- let is_admin_owned = unsafe { IsWellKnownSid(owner as _, WinBuiltinAdministratorsSid) != 0 };
+ let is_admin_owned =
+ unsafe { IsWellKnownSid(owner.cast::<c_void>(), WinBuiltinAdministratorsSid) != 0 };
// SAFETY: Since we no longer need the descriptor (or owner), it may be freed
unsafe { LocalFree(security_descriptor.cast()) };
diff --git a/windows-installer/src/windows.rs b/windows-installer/src/windows.rs
index ab7c8738b4..229c1894ae 100644
--- a/windows-installer/src/windows.rs
+++ b/windows-installer/src/windows.rs
@@ -58,7 +58,7 @@ fn write_file_to_temp(data: &[u8]) -> anyhow::Result<TempPath> {
/// Return a slice of data for the given resource
fn find_binary_data(architecture: Architecture) -> anyhow::Result<&'static [u8]> {
- let resource_id = match architecture {
+ let resource_id: usize = match architecture {
Architecture::X64 => resource::IDB_X64EXE,
Architecture::Arm64 => resource::IDB_ARM64EXE,
};
@@ -68,7 +68,7 @@ fn find_binary_data(architecture: Architecture) -> anyhow::Result<&'static [u8]>
// which is not available in windows-sys, as it is a macro.
// `resource_id` is guaranteed by the build script to refer to an actual resource.
// See https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-findresourcew
- NonZero::new(unsafe { FindResourceW(0, resource_id as _, w!("BINARY")) })
+ NonZero::new(unsafe { FindResourceW(0, resource_id as *const u16, w!("BINARY")) })
else {
bail!("Failed to find resource: {}", io::Error::last_os_error());
};