From 224872ce0345bf171cdb4a118b17e4364509d8f5 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 8 Jun 2022 01:04:33 +0300 Subject: [PATCH] Prevent null dereference on X11 with bad locale --- src/platform_impl/linux/x11/ime/context.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platform_impl/linux/x11/ime/context.rs b/src/platform_impl/linux/x11/ime/context.rs index 2fdfc6f3..f34d4bad 100644 --- a/src/platform_impl/linux/x11/ime/context.rs +++ b/src/platform_impl/linux/x11/ime/context.rs @@ -103,7 +103,14 @@ extern "C" fn preedit_draw_callback( if xim_text.encoding_is_wchar > 0 { return; } - let new_text = unsafe { CStr::from_ptr(xim_text.string.multi_byte) }; + + let new_text = unsafe { xim_text.string.multi_byte }; + + if new_text.is_null() { + return; + } + + let new_text = unsafe { CStr::from_ptr(new_text) }; String::from(new_text.to_str().expect("Invalid UTF-8 String from IME")) .chars()