Rollup merge of #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 #109859, and as a result, we received a fix PR #116476. However, it's important to note that the `libc::getuid()` never actually fails. This PR aims to clarify its safety.
This commit is contained in:
Matthias Krüger 2023-10-14 13:48:18 +02:00 committed by GitHub
commit b236d11128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}