Skip to content

Commit

Permalink
Rollup merge of rust-lang#116577 - onur-ozkan:add-safety-block-on-uns…
Browse files Browse the repository at this point in the history
…afe, r=clubby789

add `SAFETY` block on the usage of unsafe `getuid`

We pointed out this unsafe usage in rust-lang#109859, and as a result, we received a fix PR rust-lang#116476. However, it's important to note that the `libc::getuid()` never actually fails. This PR aims to clarify its safety.
  • Loading branch information
matthiaskrgr authored Oct 14, 2023
2 parents 97a9f6e + 86e9b0f commit 7f6ff13
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ impl Build {
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
let is_sudo = match env::var_os("SUDO_USER") {
Some(_sudo_user) => {
// SAFETY: getuid() system call is always successful and no return value is reserved
// to indicate an error.
//
// For more context, see https://man7.org/linux/man-pages/man2/geteuid.2.html
let uid = unsafe { libc::getuid() };
uid == 0
}
Expand Down

0 comments on commit 7f6ff13

Please sign in to comment.