nix icon indicating copy to clipboard operation
nix copied to clipboard

Change the signature of `ptrace::write` to make it safe

Open ShuiRuTian opened this issue 1 year ago • 1 comments
trafficstars

For now, the whole impl of write is

pub unsafe fn write(
    pid: Pid,
    addr: AddressType,
    data: *mut c_void,
) -> Result<()> {
    unsafe { ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop) }
}

In ptrace(2), it's mentioned data is "a word", which should be the same as the return type of read(c_long, in current code).

So, why don't we change the type of data to c_long, and make it safe?

Or maybe the type could be a byte array like [u8; sizeof::<c_long>()]

ShuiRuTian avatar Feb 27 '24 17:02 ShuiRuTian

It was made unsafe indeed for this argument, see #1245, so I think this would be a reasonable change.

SteveLauC avatar Feb 28 '24 00:02 SteveLauC