Skip to content

Commit

Permalink
Merge #1245
Browse files Browse the repository at this point in the history
1245: Make ptrace::write unsafe on Linux r=asomers a=asomers

It always should've been unsafe, because it dereferences a user-provided
pointer.

Co-authored-by: Alan Somers <asomers@gmail.com>
  • Loading branch information
bors[bot] and asomers committed May 17, 2020
2 parents fe17cb7 + 856f841 commit 2ae94eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -34,6 +34,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Changed `fallocate` return type from `c_int` to `()` (#[1201](https://github.com/nix-rust/nix/pull/1201))
- Enabled `sys::ptrace::setregs` and `sys::ptrace::getregs` on x86_64-unknown-linux-musl target
(#[1198](https://github.com/nix-rust/nix/pull/1198))
- On Linux, `ptrace::write` is now an `unsafe` function. Caveat programmer.
(#[1245](https://github.com/nix-rust/nix/pull/1245))

### Fixed

Expand Down
15 changes: 11 additions & 4 deletions src/sys/ptrace/linux.rs
Expand Up @@ -425,8 +425,15 @@ pub fn read(pid: Pid, addr: AddressType) -> Result<c_long> {
}

/// Writes a word into the processes memory at the given address
pub fn write(pid: Pid, addr: AddressType, data: *mut c_void) -> Result<()> {
unsafe {
ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop)
}
///
/// # Safety
///
/// The `data` argument is passed directly to `ptrace(2)`. Read that man page
/// for guidance.
pub unsafe fn write(
pid: Pid,
addr: AddressType,
data: *mut c_void) -> Result<()>
{
ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop)
}

0 comments on commit 2ae94eb

Please sign in to comment.