Skip to content

Commit 182bf51

Browse files
committed
rex: cast c_char to u8 in TaskStruct::get_comm()
Signed-off-by: MinhPhan8803 <[email protected]>
1 parent 046d284 commit 182bf51

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rex/src/task_struct.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ impl TaskStruct {
4949
// a user-provided buffer, here we can take advantage of Rust's ownership by
5050
// just providing a reference to the CString instead
5151
pub fn get_comm(&self) -> Result<&CStr, ffi::FromBytesUntilNulError> {
52-
CStr::from_bytes_until_nul(&self.kptr.comm[..])
52+
// casting from c_char to u8 is sound, see:
53+
// https://doc.rust-lang.org/stable/src/core/ffi/c_str.rs.html#276-288
54+
let comm_bytes =
55+
unsafe { &*(&self.kptr.comm[..] as *const _ as *const [u8]) };
56+
CStr::from_bytes_until_nul(comm_bytes)
5357
}
5458

5559
pub fn get_pt_regs(&self) -> &'static PtRegs {

0 commit comments

Comments
 (0)