From 86e9b0f0d4881787bed2ff77d3bb6db56d077ee2 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Mon, 9 Oct 2023 21:43:33 +0300 Subject: [PATCH] add `SAFETY` block on usage of unsafe `getuid` Signed-off-by: onur-ozkan --- src/bootstrap/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 5c78015e560..0ac856479f8 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -368,6 +368,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 }