Skip to content

Commit

Permalink
Move swkbd_message_callback sanity checks to the top of the fn
Browse files Browse the repository at this point in the history
It's kinda pointless to have those checks *after* attempting to deref
the data rather than before.
  • Loading branch information
FenrirWolf committed Feb 21, 2024
1 parent 9ed5878 commit b35c500
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ctru-rs/src/applets/swkbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ bitflags! {
}

// Internal book-keeping struct used to send data to `aptSetMessageCallback` when calling the software keyboard.
#[derive(Copy, Clone)]
struct MessageCallbackData {
filter_callback: *const Box<CallbackFunction>,
swkbd_shared_mem_ptr: *mut libc::c_void,
Expand Down Expand Up @@ -803,15 +804,15 @@ impl SoftwareKeyboard {
msg: *mut libc::c_void,
msg_size: libc::size_t,
) {
let data = unsafe { &mut *user.cast::<MessageCallbackData>() };
let swkbd = unsafe { &mut *msg.cast::<SwkbdState>() };

if sender != ctru_sys::APPID_SOFTWARE_KEYBOARD
|| msg_size != std::mem::size_of::<SwkbdState>()
{
return;
}

let swkbd = unsafe { &mut *msg.cast::<SwkbdState>() };
let data = unsafe { *user.cast::<MessageCallbackData>() };

let text16 = unsafe {
widestring::Utf16Str::from_slice_unchecked(std::slice::from_raw_parts(
data.swkbd_shared_mem_ptr.add(swkbd.text_offset as _).cast(),
Expand Down

0 comments on commit b35c500

Please sign in to comment.