Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn_to_numeric_cast_any = "warn"
ptr_cast_constness = "warn"
unnecessary_safety_comment = "warn"
missing_safety_doc = "warn"
as_pointer_underscore = "warn"

[workspace.dependencies]
uuid = { version = "1.18", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion ffi/src/dpapi/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod inner {
// - `destination` is guaranteed to be non-null due to the prior check.
// - The memory region `destination` contains a valid null-terminator at the end of string.
// - The memory region `destination` points to is valid for reads of bytes up to and including null-terminator.
let destination = unsafe { CStr::from_ptr(destination as *const _) }.to_str().unwrap();
let destination = unsafe { CStr::from_ptr(destination.cast()) }.to_str().unwrap();

println!("session id: {:?}. destination: {:?}.", session_id, destination);

Expand Down
22 changes: 11 additions & 11 deletions ffi/src/dpapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub unsafe extern "system" fn DpapiProtectSecret(
// - `sid` is guaranteed to be non-null due to the prior check.
// - The memory region `sid` contains a valid null-terminator at the end of string.
// - The memory region `sid` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(sid as *const _) }.to_str(),
unsafe { CStr::from_ptr(sid.cast()) }.to_str(),
NTE_INVALID_PARAMETER
)
.to_owned();
Expand All @@ -118,23 +118,23 @@ pub unsafe extern "system" fn DpapiProtectSecret(
// - `server` is guaranteed to be non-null due to the prior check.
// - The memory region `server` contains a valid null-terminator at the end of string.
// - The memory region `server` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(server as *const _) }.to_str(),
unsafe { CStr::from_ptr(server.cast()) }.to_str(),
NTE_INVALID_PARAMETER
);
let username = try_execute!(
// SAFETY:
// - `username` is guaranteed to be non-null due to the prior check.
// - The memory region `username` contains a valid null-terminator at the end of string.
// - The memory region `username` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(username as *const _) }.to_str(),
unsafe { CStr::from_ptr(username.cast()) }.to_str(),
NTE_INVALID_PARAMETER
);
let password = try_execute!(
// SAFETY:
// - `password` is guaranteed to be non-null due to the prior check.
// - The memory region `password` contains a valid null-terminator at the end of string.
// - The memory region `password` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(password as *const _) }.to_str(),
unsafe { CStr::from_ptr(password.cast()) }.to_str(),
NTE_INVALID_PARAMETER
)
.to_owned();
Expand All @@ -145,7 +145,7 @@ pub unsafe extern "system" fn DpapiProtectSecret(
// - `computer_name` is guaranteed to be non-null due to the prior check.
// - The memory region `computer_name` contains a valid null-terminator at the end of string.
// - The memory region `computer_name` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(computer_name as *const _) }.to_str(),
unsafe { CStr::from_ptr(computer_name.cast()) }.to_str(),
NTE_INVALID_PARAMETER
)
.to_owned(),
Expand All @@ -162,7 +162,7 @@ pub unsafe extern "system" fn DpapiProtectSecret(
// - `proxy_url` is guaranteed to be non-null due to the prior check.
// - The memory region `proxy_url` contains a valid null-terminator at the end of string.
// - The memory region `proxy_url` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(proxy_url as *const _) }.to_str(),
unsafe { CStr::from_ptr(proxy_url.cast()) }.to_str(),
NTE_INVALID_PARAMETER
);

Expand Down Expand Up @@ -290,23 +290,23 @@ pub unsafe extern "system" fn DpapiUnprotectSecret(
// - `server` is guaranteed to be non-null due to the prior check.
// - The memory region `server` contains a valid null-terminator at the end of string.
// - The memory region `server` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(server as *const _) }.to_str(),
unsafe { CStr::from_ptr(server.cast()) }.to_str(),
NTE_INVALID_PARAMETER
);
let username = try_execute!(
// SAFETY:
// - `username` is guaranteed to be non-null due to the prior check.
// - The memory region `username` contains a valid null-terminator at the end of string.
// - The memory region `username` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(username as *const _) }.to_str(),
unsafe { CStr::from_ptr(username.cast()) }.to_str(),
NTE_INVALID_PARAMETER
);
let password = try_execute!(
// SAFETY:
// - `password` is guaranteed to be non-null due to the prior check.
// - The memory region `password` contains a valid null-terminator at the end of string.
// - The memory region `password` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(password as *const _) }.to_str(),
unsafe { CStr::from_ptr(password.cast()) }.to_str(),
NTE_INVALID_PARAMETER
)
.to_owned();
Expand All @@ -317,7 +317,7 @@ pub unsafe extern "system" fn DpapiUnprotectSecret(
// - `computer_name` is guaranteed to be non-null due to the prior check.
// - The memory region `computer_name` contains a valid null-terminator at the end of string.
// - The memory region `computer_name` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(computer_name as *const _) }.to_str(),
unsafe { CStr::from_ptr(computer_name.cast()) }.to_str(),
NTE_INVALID_PARAMETER
)
.to_owned(),
Expand All @@ -334,7 +334,7 @@ pub unsafe extern "system" fn DpapiUnprotectSecret(
// - `proxy_url` is guaranteed to be non-null due to the prior check.
// - The memory region `proxy_url` contains a valid null-terminator at the end of string.
// - The memory region `proxy_url` points to is valid for reads of bytes up to and including null-terminator.
unsafe { CStr::from_ptr(proxy_url as *const _) }.to_str(),
unsafe { CStr::from_ptr(proxy_url.cast()) }.to_str(),
NTE_INVALID_PARAMETER
);

Expand Down
2 changes: 1 addition & 1 deletion ffi/src/dpapi/session_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(super) unsafe fn session_token_fn(get_session_token: CGetSessionTokenFn) ->
let status = unsafe {
get_session_token(
&session_id,
destination.as_ptr() as *const _,
destination.as_ptr().cast(),
token_buf.as_mut_ptr(),
&mut token_len,
)
Expand Down
12 changes: 6 additions & 6 deletions ffi/src/sspi/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ unsafe fn copy_decrypted_buffers(to_buffers: PSecBuffer, from_buffers: Vec<Secur
if from_buffer.buffer_type() != BufferType::Missing {
// We don't need to copy the actual content of the buffer because [from_buffer] is created
// from the C-input-buffer and all decryption is performed in-place.
to_buffer.pv_buffer = from_buffer.take_data().as_mut_ptr() as *mut _;
to_buffer.pv_buffer = from_buffer.take_data().as_mut_ptr().cast();
}
}

Expand Down Expand Up @@ -724,7 +724,7 @@ mod tests {
SecBuffer {
cb_buffer: stream_buffer_data_len,
buffer_type: 10,
pv_buffer: stream_buffer_data.as_mut_ptr() as *mut _,
pv_buffer: stream_buffer_data.as_mut_ptr().cast(),
},
SecBuffer {
cb_buffer: 0,
Expand Down Expand Up @@ -781,12 +781,12 @@ mod tests {
SecBuffer {
cb_buffer: token.len().try_into().unwrap(),
buffer_type: 2, // Token
pv_buffer: token.as_mut_ptr() as *mut _,
pv_buffer: token.as_mut_ptr().cast(),
},
SecBuffer {
cb_buffer: data.len().try_into().unwrap(),
buffer_type: 1, // Data
pv_buffer: data.as_mut_ptr() as *mut _,
pv_buffer: data.as_mut_ptr().cast(),
},
];
let mut message = SecBufferDesc {
Expand All @@ -811,12 +811,12 @@ mod tests {
SecBuffer {
cb_buffer: token.len().try_into().unwrap(),
buffer_type: 2, // Token
pv_buffer: token.as_mut_ptr() as *mut _,
pv_buffer: token.as_mut_ptr().cast(),
},
SecBuffer {
cb_buffer: data.len().try_into().unwrap(),
buffer_type: 1, // Data
pv_buffer: data.as_mut_ptr() as *mut _,
pv_buffer: data.as_mut_ptr().cast(),
},
];
let mut message = SecBufferDesc {
Expand Down
5 changes: 2 additions & 3 deletions ffi/src/sspi/credentials_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ pub unsafe fn extract_kdc_proxy_settings(p_buffer: NonNull<c_void>) -> Result<Kd
// - `proxy_server_length` is valid.
let proxy_server = String::from_utf16(unsafe {
from_raw_parts(proxy_server_ptr, *proxy_server_length as usize / size_of::<SecWChar>())
})
.map_err(Error::from)?;
})?;

let client_tls_cred = if *client_tls_cred_offset != 0 && *client_tls_cred_length != 0 {
// SAFETY:
Expand All @@ -131,7 +130,7 @@ pub unsafe fn extract_kdc_proxy_settings(p_buffer: NonNull<c_void>) -> Result<Kd
// - `client_tls_cred_length` is valid.
let client_tls_cred_data = unsafe { from_raw_parts(client_tls_cred_ptr, *client_tls_cred_length as usize) };

let client_tls_cred = String::from_utf16(client_tls_cred_data).map_err(Error::from)?;
let client_tls_cred = String::from_utf16(client_tls_cred_data)?;

Some(client_tls_cred)
} else {
Expand Down
Loading