Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macos): IPC crashes with invalid body types, ref #1097 #1222

Merged
merged 1 commit into from
Apr 17, 2024
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
5 changes: 5 additions & 0 deletions .changes/ipc-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fix IPC crash on wkwebview if receiving invalid types.
13 changes: 9 additions & 4 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ impl InnerWebView {
let function =
&mut *(*function as *mut (Box<dyn for<'r> Fn(&'r Window, String)>, Rc<Window>));
let body: id = msg_send![msg, body];
let utf8: *const c_char = msg_send![body, UTF8String];
if let Ok(js) = CStr::from_ptr(utf8).to_str() {
(function.0)(&function.1, js.to_string());
let is_string: bool = msg_send![body, isKindOfClass: class!(NSString)];
if is_string {
let utf8: *const c_char = msg_send![body, UTF8String];
if let Ok(js) = CStr::from_ptr(utf8).to_str() {
(function.0)(&function.1, js.to_string());
} else {
log::warn!("WebView received invalid UTF8 string from IPC.");
}
} else {
log::warn!("WebView received invalid UTF8 string from IPC.");
log::warn!("WebView received invalid IPC call.");
}
} else {
log::warn!("WebView instance is dropped! This handler shouldn't be called.");
Expand Down
Loading