summary refs log tree commit diff
path: root/gpu_display
diff options
context:
space:
mode:
Diffstat (limited to 'gpu_display')
-rw-r--r--gpu_display/src/gpu_display_wl.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/gpu_display/src/gpu_display_wl.rs b/gpu_display/src/gpu_display_wl.rs
index a079d87..670c429 100644
--- a/gpu_display/src/gpu_display_wl.rs
+++ b/gpu_display/src/gpu_display_wl.rs
@@ -111,8 +111,14 @@ impl DisplayWl {
             Some(None) => return Err(GpuDisplayError::InvalidPath),
             None => None,
         };
-        let setup_success =
-            unsafe { dwl_context_setup(ctx.0, cstr_path.map(|s| s.as_ptr()).unwrap_or(null())) };
+        // This grabs a pointer to cstr_path without moving the CString into the .map closure
+        // accidentally, which triggeres a really hard to catch use after free in
+        // dwl_context_setup.
+        let cstr_path_ptr = cstr_path
+            .as_ref()
+            .map(|s: &CString| CStr::as_ptr(s))
+            .unwrap_or(null());
+        let setup_success = unsafe { dwl_context_setup(ctx.0, cstr_path_ptr) };
         if !setup_success {
             return Err(GpuDisplayError::Connect);
         }