Skip to content

Commit

Permalink
Further constrain transforming array parameters to avoid potentially …
Browse files Browse the repository at this point in the history
…polymorphic types (#2046)
  • Loading branch information
kennykerr authored Sep 21, 2022
1 parent dd244b5 commit e018d41
Show file tree
Hide file tree
Showing 96 changed files with 2,541 additions and 3,003 deletions.
19 changes: 10 additions & 9 deletions crates/libs/metadata/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,6 @@ impl<'a> Reader<'a> {
})
.collect();

// Remove any byte arrays that aren't byte-sized types.
for param in &mut params {
if let ArrayInfo::RelativeByteLen(_) = param.array_info {
if !param.ty.is_byte_size() {
param.array_info = ArrayInfo::None
}
}
}

for position in 0..params.len() {
// Point len params back to the corresponding ptr params.
match params[position].array_info {
Expand Down Expand Up @@ -592,6 +583,16 @@ impl<'a> Reader<'a> {
}
}

// Remove any byte arrays that aren't byte-sized types.
for position in 0..params.len() {
if let ArrayInfo::RelativeByteLen(relative) = params[position].array_info {
if !params[position].ty.is_byte_size() {
params[position].array_info = ArrayInfo::None;
params[relative].array_info = ArrayInfo::None;
}
}
}

Signature { def: row, params, return_type }
}
pub fn method_def_extern_abi(&self, def: MethodDef) -> &'static str {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/metadata/src/reader/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Type {
pub fn is_byte_size(&self) -> bool {
match self {
Type::ConstPtr((kind, _)) | Type::MutPtr((kind, _)) => kind.is_byte_size(),
Type::I8 | Type::U8 | Type::Void | Type::PSTR | Type::PCSTR => true,
Type::I8 | Type::U8 | Type::PSTR | Type::PCSTR => true,
_ => false,
}
}
Expand Down

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/libs/windows/src/Windows/Win32/Devices/AllJoyn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,28 +196,28 @@ where
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
#[inline]
pub unsafe fn AllJoynReceiveFromBus<'a, P0>(connectedbushandle: P0, buffer: ::core::option::Option<&mut [u8]>, bytestransferred: ::core::option::Option<*mut u32>, reserved: *mut ::core::ffi::c_void) -> super::super::Foundation::BOOL
pub unsafe fn AllJoynReceiveFromBus<'a, P0>(connectedbushandle: P0, buffer: ::core::option::Option<*mut ::core::ffi::c_void>, bytestoread: u32, bytestransferred: ::core::option::Option<*mut u32>, reserved: *mut ::core::ffi::c_void) -> super::super::Foundation::BOOL
where
P0: ::std::convert::Into<super::super::Foundation::HANDLE>,
{
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
fn AllJoynReceiveFromBus(connectedbushandle: super::super::Foundation::HANDLE, buffer: *mut ::core::ffi::c_void, bytestoread: u32, bytestransferred: *mut u32, reserved: *mut ::core::ffi::c_void) -> super::super::Foundation::BOOL;
}
AllJoynReceiveFromBus(connectedbushandle.into(), ::core::mem::transmute(buffer.as_deref().map_or(::core::ptr::null(), |slice| slice.as_ptr())), buffer.as_deref().map_or(0, |slice| slice.len() as _), ::core::mem::transmute(bytestransferred.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(reserved))
AllJoynReceiveFromBus(connectedbushandle.into(), ::core::mem::transmute(buffer.unwrap_or(::std::ptr::null_mut())), bytestoread, ::core::mem::transmute(bytestransferred.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(reserved))
}
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`, `\"Win32_Foundation\"`*"]
#[cfg(feature = "Win32_Foundation")]
#[inline]
pub unsafe fn AllJoynSendToBus<'a, P0>(connectedbushandle: P0, buffer: ::core::option::Option<&[u8]>, bytestransferred: ::core::option::Option<*mut u32>, reserved: *mut ::core::ffi::c_void) -> super::super::Foundation::BOOL
pub unsafe fn AllJoynSendToBus<'a, P0>(connectedbushandle: P0, buffer: ::core::option::Option<*const ::core::ffi::c_void>, bytestowrite: u32, bytestransferred: ::core::option::Option<*mut u32>, reserved: *mut ::core::ffi::c_void) -> super::super::Foundation::BOOL
where
P0: ::std::convert::Into<super::super::Foundation::HANDLE>,
{
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
fn AllJoynSendToBus(connectedbushandle: super::super::Foundation::HANDLE, buffer: *const ::core::ffi::c_void, bytestowrite: u32, bytestransferred: *mut u32, reserved: *mut ::core::ffi::c_void) -> super::super::Foundation::BOOL;
}
AllJoynSendToBus(connectedbushandle.into(), ::core::mem::transmute(buffer.as_deref().map_or(::core::ptr::null(), |slice| slice.as_ptr())), buffer.as_deref().map_or(0, |slice| slice.len() as _), ::core::mem::transmute(bytestransferred.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(reserved))
AllJoynSendToBus(connectedbushandle.into(), ::core::mem::transmute(buffer.unwrap_or(::std::ptr::null())), bytestowrite, ::core::mem::transmute(bytestransferred.unwrap_or(::std::ptr::null_mut())), ::core::mem::transmute(reserved))
}
#[doc = "*Required features: `\"Win32_Devices_AllJoyn\"`*"]
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,12 @@ pub unsafe fn WinBioSetCredential(r#type: WINBIO_CREDENTIAL_TYPE, credential: &[
}
#[doc = "*Required features: `\"Win32_Devices_BiometricFramework\"`*"]
#[inline]
pub unsafe fn WinBioSetProperty(sessionhandle: u32, propertytype: u32, propertyid: u32, unitid: u32, identity: ::core::option::Option<*const WINBIO_IDENTITY>, subfactor: u8, propertybuffer: &[u8]) -> ::windows::core::Result<()> {
pub unsafe fn WinBioSetProperty(sessionhandle: u32, propertytype: u32, propertyid: u32, unitid: u32, identity: ::core::option::Option<*const WINBIO_IDENTITY>, subfactor: u8, propertybuffer: *const ::core::ffi::c_void, propertybuffersize: usize) -> ::windows::core::Result<()> {
#[cfg_attr(windows, link(name = "windows"))]
extern "system" {
fn WinBioSetProperty(sessionhandle: u32, propertytype: u32, propertyid: u32, unitid: u32, identity: *const WINBIO_IDENTITY, subfactor: u8, propertybuffer: *const ::core::ffi::c_void, propertybuffersize: usize) -> ::windows::core::HRESULT;
}
WinBioSetProperty(sessionhandle, propertytype, propertyid, unitid, ::core::mem::transmute(identity.unwrap_or(::std::ptr::null())), subfactor, ::core::mem::transmute(propertybuffer.as_ptr()), propertybuffer.len() as _).ok()
WinBioSetProperty(sessionhandle, propertytype, propertyid, unitid, ::core::mem::transmute(identity.unwrap_or(::std::ptr::null())), subfactor, ::core::mem::transmute(propertybuffer), propertybuffersize).ok()
}
#[doc = "*Required features: `\"Win32_Devices_BiometricFramework\"`*"]
#[inline]
Expand Down
Loading

0 comments on commit e018d41

Please sign in to comment.