a2c4e63c73
resolves: RHEL-45465
41 lines
1.6 KiB
Diff
41 lines
1.6 KiB
Diff
From a5bc2980ec85d04ad1905d299b7b8c083c26965f Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?J=C3=BCrgen=20H=C3=B6tzel?= <juergen@archlinux.org>
|
|
Date: Thu, 20 Jun 2024 13:27:51 +0100
|
|
Subject: [PATCH] rust: Handle null pointer when creating slice
|
|
|
|
Starting with Rust 1.78 null assertions in the standard library are
|
|
now checked when compiling in test/debug mode.
|
|
|
|
Fixes: https://github.com/libguestfs/libguestfs/issues/145
|
|
(cherry picked from commit 43946911c7e4eda422b8d041e063689e7434b04e)
|
|
---
|
|
rust/src/event.rs | 12 ++++++++++--
|
|
1 file changed, 10 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/rust/src/event.rs b/rust/src/event.rs
|
|
index 752e73610..72afd3cf6 100644
|
|
--- a/rust/src/event.rs
|
|
+++ b/rust/src/event.rs
|
|
@@ -105,8 +105,16 @@ impl<'a> base::Handle<'a> {
|
|
None => panic!("Failed to parse bitmask: {}", event),
|
|
};
|
|
let eh = EventHandle { eh: event_handle };
|
|
- let buf = unsafe { slice::from_raw_parts(buf as *const u8, buf_len) };
|
|
- let array = unsafe { slice::from_raw_parts(array, array_len) };
|
|
+ let buf = if !buf.is_null() {
|
|
+ unsafe { slice::from_raw_parts(buf as *const u8, buf_len) }
|
|
+ } else {
|
|
+ &[]
|
|
+ };
|
|
+ let array = if !array.is_null() {
|
|
+ unsafe { slice::from_raw_parts(array, array_len) }
|
|
+ } else {
|
|
+ &[]
|
|
+ };
|
|
|
|
let callback: &Box<dyn Fn(guestfs::Event, EventHandle, &[u8], &[u64])> =
|
|
Box::leak(unsafe { Box::from_raw(opaque as *mut _) });
|
|
--
|
|
2.43.0
|
|
|