Skip to content

Commit 7f6ff13

Browse files
authored
Rollup merge of rust-lang#116577 - onur-ozkan:add-safety-block-on-unsafe, 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.
2 parents 97a9f6e + 86e9b0f commit 7f6ff13

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/bootstrap/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ impl Build {
359359
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
360360
let is_sudo = match env::var_os("SUDO_USER") {
361361
Some(_sudo_user) => {
362+
// SAFETY: getuid() system call is always successful and no return value is reserved
363+
// to indicate an error.
364+
//
365+
// For more context, see https://man7.org/linux/man-pages/man2/geteuid.2.html
362366
let uid = unsafe { libc::getuid() };
363367
uid == 0
364368
}

0 commit comments

Comments
 (0)