From 3e4d93dfff534acf62053b802c6a549f38e9b0f6 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sun, 25 Jul 2021 01:49:43 +0200 Subject: [PATCH] egl: Fix segfault in egl logging for empty command strings --- src/backend/egl/ffi.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/egl/ffi.rs b/src/backend/egl/ffi.rs index 0f4599e..9d90561 100644 --- a/src/backend/egl/ffi.rs +++ b/src/backend/egl/ffi.rs @@ -27,8 +27,12 @@ extern "system" fn egl_debug_log( let _ = std::panic::catch_unwind(move || unsafe { let msg = std::ffi::CStr::from_ptr(message as *const _); let message_utf8 = msg.to_string_lossy(); - let cmd = std::ffi::CStr::from_ptr(command as *const _); - let command_utf8 = cmd.to_string_lossy(); + let command_utf8 = if !command.is_null() { + let cmd = std::ffi::CStr::from_ptr(command as *const _); + cmd.to_string_lossy() + } else { + std::borrow::Cow::Borrowed("") + }; let logger = crate::slog_or_fallback(None).new(slog::o!("backend" => "egl")); match severity { egl::DEBUG_MSG_CRITICAL_KHR | egl::DEBUG_MSG_ERROR_KHR => {