Skip to content

Commit

Permalink
fix: fix wkwebview crashed when received invalid UTF8 string from IPC (
Browse files Browse the repository at this point in the history
  • Loading branch information
wusyong authored Nov 20, 2023
1 parent 8790786 commit c78c69b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-expect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"wry": patch
---

Fix wkwebview crashed when received invalid UTF8 string from IPC.

8 changes: 5 additions & 3 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ impl InnerWebView {
&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];
let js = CStr::from_ptr(utf8).to_str().expect("Invalid UTF8 string");

(function.0)(&function.1, js.to_string());
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 instance is dropped! This handler shouldn't be called.");
}
Expand Down

0 comments on commit c78c69b

Please sign in to comment.