Skip to content

Commit

Permalink
Fix wkwebview crashed when received invalid UTF8 string from IPC (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
wusyong authored Nov 20, 2023
1 parent 15ae3c7 commit 10229e2
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/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ impl InnerWebView {
let function = &mut *(*function as *mut Box<dyn Fn(String)>);
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)(js.to_string());
if let Ok(js) = CStr::from_ptr(utf8).to_str() {
(function)(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 10229e2

Please sign in to comment.