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: fix wkwebview crashed when received invalid UTF8 string from IPC (#1084) #1085

Merged
merged 1 commit into from
Nov 20, 2023
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
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
Loading