[libc-commits] [libc] [libc] Implement seteuid and setegid in unistd (PR #233088)

Aman Maurya via libc-commits libc-commits at lists.llvm.org
Sat Oct 17 07:04:33 PDT 2026


https://github.com/amanmaurya92 created https://github.com/llvm/llvm-project/pull/233088

Implement the standard POSIX functions `seteuid` and `setegid` in `<unistd.h>`.

Fixes #232380.

Assisted by Antigravity and reviewed by Aman Maurya.

>From cb91cc2c1999c179bc36615c3ca81ab0daad17b7 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Sat, 17 Oct 2026 17:33:19 +0530
Subject: [PATCH] [libc] Implement seteuid and setegid in unistd

Implement the standard POSIX functions seteuid and setegid in <unistd.h>.
- Add syscall wrappers for setresuid and setresgid on Linux.
- Implement seteuid and setegid via setresuid(-1, uid, -1) and setresgid(-1, gid, -1).
- Declare entrypoints in unistd.yaml and register them across Linux target entrypoints.
- Add unit tests covering current EUID/UID/EGID/GID and unprivileged invalid ID behavior.

Fixes #232380.
---
 libc/config/linux/aarch64/entrypoints.txt     |  2 +
 libc/config/linux/arm/entrypoints.txt         |  2 +
 libc/config/linux/riscv/entrypoints.txt       |  2 +
 libc/config/linux/x86_64/entrypoints.txt      |  2 +
 libc/include/unistd.yaml                      | 12 ++++++
 .../linux/syscall_wrappers/CMakeLists.txt     | 26 ++++++++++++
 .../OSUtil/linux/syscall_wrappers/setresgid.h | 40 +++++++++++++++++++
 .../OSUtil/linux/syscall_wrappers/setresuid.h | 40 +++++++++++++++++++
 libc/src/unistd/CMakeLists.txt                | 14 +++++++
 libc/src/unistd/linux/CMakeLists.txt          | 24 +++++++++++
 libc/src/unistd/linux/setegid.cpp             | 34 ++++++++++++++++
 libc/src/unistd/linux/seteuid.cpp             | 34 ++++++++++++++++
 libc/src/unistd/setegid.h                     | 26 ++++++++++++
 libc/src/unistd/seteuid.h                     | 26 ++++++++++++
 libc/test/src/unistd/CMakeLists.txt           | 30 ++++++++++++++
 libc/test/src/unistd/setegid_test.cpp         | 40 +++++++++++++++++++
 libc/test/src/unistd/seteuid_test.cpp         | 40 +++++++++++++++++++
 17 files changed, 394 insertions(+)
 create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/setresgid.h
 create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/setresuid.h
 create mode 100644 libc/src/unistd/linux/setegid.cpp
 create mode 100644 libc/src/unistd/linux/seteuid.cpp
 create mode 100644 libc/src/unistd/setegid.h
 create mode 100644 libc/src/unistd/seteuid.h
 create mode 100644 libc/test/src/unistd/setegid_test.cpp
 create mode 100644 libc/test/src/unistd/seteuid_test.cpp

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index b2c8d62a65f4e1..aeab09a2dae101 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -501,6 +501,8 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.readlink
     libc.src.unistd.readlinkat
     libc.src.unistd.rmdir
+    libc.src.unistd.setegid
+    libc.src.unistd.seteuid
     libc.src.unistd.setgid
     libc.src.unistd.setpgid
     libc.src.unistd.setregid
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 023d298170c245..28979790164f11 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -294,6 +294,8 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.readlink
     libc.src.unistd.readlinkat
     libc.src.unistd.rmdir
+    libc.src.unistd.setegid
+    libc.src.unistd.seteuid
     libc.src.unistd.setgid
     libc.src.unistd.setpgid
     libc.src.unistd.setregid
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 3bdc686c0e4ce4..5842a405a599c2 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -521,6 +521,8 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.readlink
     libc.src.unistd.readlinkat
     libc.src.unistd.rmdir
+    libc.src.unistd.setegid
+    libc.src.unistd.seteuid
     libc.src.unistd.setgid
     libc.src.unistd.setpgid
     libc.src.unistd.setregid
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 23a588f65d7435..90bd0ac5aef553 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -541,6 +541,8 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.readlink
     libc.src.unistd.readlinkat
     libc.src.unistd.rmdir
+    libc.src.unistd.setegid
+    libc.src.unistd.seteuid
     libc.src.unistd.setgid
     libc.src.unistd.setpgid
     libc.src.unistd.setregid
diff --git a/libc/include/unistd.yaml b/libc/include/unistd.yaml
index 5964e35b6ce5d2..1e4b04590f2c77 100644
--- a/libc/include/unistd.yaml
+++ b/libc/include/unistd.yaml
@@ -543,6 +543,18 @@ functions:
       - type: const void *__restrict
       - type: void *
       - type: ssize_t
+  - name: setegid
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: gid_t
+  - name: seteuid
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: uid_t
   - name: setgid
     standards:
       - posix
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 3f2ed1852acee2..ed265cda2ee3f7 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -923,6 +923,32 @@ add_header_library(
     libc.src.__support.OSUtil.osutil
 )
 
+add_header_library(
+  setresgid
+  HDRS
+    setresgid.h
+  DEPENDS
+    libc.hdr.types.gid_t
+    libc.include.sys_syscall
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.src.__support.OSUtil.osutil
+)
+
+add_header_library(
+  setresuid
+  HDRS
+    setresuid.h
+  DEPENDS
+    libc.hdr.types.uid_t
+    libc.include.sys_syscall
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.src.__support.OSUtil.osutil
+)
+
 add_header_library(
   setreuid
   HDRS
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setresgid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/setresgid.h
new file mode 100644
index 00000000000000..df68ca97d78e56
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setresgid.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for setresgid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETRESGID_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETRESGID_H
+
+#include "hdr/types/gid_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> setresgid(gid_t rgid, gid_t egid, gid_t sgid) {
+#if defined(SYS_setresgid32)
+  return syscall_checked<int>(SYS_setresgid32, rgid, egid, sgid);
+#elif defined(SYS_setresgid)
+  return syscall_checked<int>(SYS_setresgid, rgid, egid, sgid);
+#else
+#error "SYS_setresgid and SYS_setresgid32 syscalls not available."
+#endif
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETRESGID_H
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setresuid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/setresuid.h
new file mode 100644
index 00000000000000..4574e9a28a6f67
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setresuid.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for setresuid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETRESUID_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETRESUID_H
+
+#include "hdr/types/uid_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> setresuid(uid_t ruid, uid_t euid, uid_t suid) {
+#if defined(SYS_setresuid32)
+  return syscall_checked<int>(SYS_setresuid32, ruid, euid, suid);
+#elif defined(SYS_setresuid)
+  return syscall_checked<int>(SYS_setresuid, ruid, euid, suid);
+#else
+#error "SYS_setresuid and SYS_setresuid32 syscalls not available."
+#endif
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SETRESUID_H
diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt
index 27b74b8ca2de3c..e50705a2cb1adc 100644
--- a/libc/src/unistd/CMakeLists.txt
+++ b/libc/src/unistd/CMakeLists.txt
@@ -399,6 +399,20 @@ add_entrypoint_object(
     .${LIBC_TARGET_OS}.rmdir
 )
 
+add_entrypoint_object(
+  setegid
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.setegid
+)
+
+add_entrypoint_object(
+  seteuid
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.seteuid
+)
+
 add_entrypoint_object(
   setgid
   ALIAS
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 61030ec7e12283..e71304a05cbd49 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -718,6 +718,30 @@ add_entrypoint_object(
     libc.src.errno.errno
 )
 
+add_entrypoint_object(
+  setegid
+  SRCS
+    setegid.cpp
+  HDRS
+    ../setegid.h
+  DEPENDS
+    libc.hdr.types.gid_t
+    libc.src.__support.OSUtil.linux.syscall_wrappers.setresgid
+    libc.src.errno.errno
+)
+
+add_entrypoint_object(
+  seteuid
+  SRCS
+    seteuid.cpp
+  HDRS
+    ../seteuid.h
+  DEPENDS
+    libc.hdr.types.uid_t
+    libc.src.__support.OSUtil.linux.syscall_wrappers.setresuid
+    libc.src.errno.errno
+)
+
 add_entrypoint_object(
   setgid
   SRCS
diff --git a/libc/src/unistd/linux/setegid.cpp b/libc/src/unistd/linux/setegid.cpp
new file mode 100644
index 00000000000000..05c9c15c120e08
--- /dev/null
+++ b/libc/src/unistd/linux/setegid.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of setegid.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/setegid.h"
+
+#include "hdr/types/gid_t.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/setresgid.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, setegid, (gid_t gid)) {
+  auto ret = linux_syscalls::setresgid(static_cast<gid_t>(-1), gid,
+                                       static_cast<gid_t>(-1));
+  if (!ret) {
+    libc_errno = ret.error();
+    return -1;
+  }
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/unistd/linux/seteuid.cpp b/libc/src/unistd/linux/seteuid.cpp
new file mode 100644
index 00000000000000..9be20d34fea466
--- /dev/null
+++ b/libc/src/unistd/linux/seteuid.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of seteuid.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/seteuid.h"
+
+#include "hdr/types/uid_t.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/setresuid.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, seteuid, (uid_t uid)) {
+  auto ret = linux_syscalls::setresuid(static_cast<uid_t>(-1), uid,
+                                       static_cast<uid_t>(-1));
+  if (!ret) {
+    libc_errno = ret.error();
+    return -1;
+  }
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/unistd/setegid.h b/libc/src/unistd/setegid.h
new file mode 100644
index 00000000000000..814e0d15b6c98d
--- /dev/null
+++ b/libc/src/unistd/setegid.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for setegid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_UNISTD_SETEGID_H
+#define LLVM_LIBC_SRC_UNISTD_SETEGID_H
+
+#include "hdr/types/gid_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int setegid(gid_t gid);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_UNISTD_SETEGID_H
diff --git a/libc/src/unistd/seteuid.h b/libc/src/unistd/seteuid.h
new file mode 100644
index 00000000000000..efcae1f180f557
--- /dev/null
+++ b/libc/src/unistd/seteuid.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for seteuid.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_UNISTD_SETEUID_H
+#define LLVM_LIBC_SRC_UNISTD_SETEUID_H
+
+#include "hdr/types/uid_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int seteuid(uid_t uid);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_UNISTD_SETEUID_H
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index 2e8d9bb8e2509f..08e42e3fe4c643 100644
--- a/libc/test/src/unistd/CMakeLists.txt
+++ b/libc/test/src/unistd/CMakeLists.txt
@@ -497,6 +497,36 @@ add_libc_test(
     libc.test.UnitTest.ErrnoSetterMatcher
 )
 
+add_libc_test(
+  setegid_test
+  SUITE
+    libc_unistd_unittests
+  SRCS
+    setegid_test.cpp
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.src.unistd.getegid
+    libc.src.unistd.getgid
+    libc.src.unistd.setegid
+    libc.test.UnitTest.ErrnoCheckingTest
+    libc.test.UnitTest.ErrnoSetterMatcher
+)
+
+add_libc_test(
+  seteuid_test
+  SUITE
+    libc_unistd_unittests
+  SRCS
+    seteuid_test.cpp
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.src.unistd.geteuid
+    libc.src.unistd.getuid
+    libc.src.unistd.seteuid
+    libc.test.UnitTest.ErrnoCheckingTest
+    libc.test.UnitTest.ErrnoSetterMatcher
+)
+
 add_libc_test(
   setgid_test
   SUITE
diff --git a/libc/test/src/unistd/setegid_test.cpp b/libc/test/src/unistd/setegid_test.cpp
new file mode 100644
index 00000000000000..3f1cb78d5a8a37
--- /dev/null
+++ b/libc/test/src/unistd/setegid_test.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for setegid.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "src/unistd/getegid.h"
+#include "src/unistd/getgid.h"
+#include "src/unistd/setegid.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+using LlvmLibcSetEGidTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcSetEGidTest, SetCurrentEGid) {
+  // Setting the effective GID to the current effective GID should succeed.
+  ASSERT_THAT(LIBC_NAMESPACE::setegid(LIBC_NAMESPACE::getegid()), Succeeds());
+}
+
+TEST_F(LlvmLibcSetEGidTest, SetCurrentGid) {
+  // Setting the effective GID to the current real GID should succeed.
+  ASSERT_THAT(LIBC_NAMESPACE::setegid(LIBC_NAMESPACE::getgid()), Succeeds());
+}
+
+TEST_F(LlvmLibcSetEGidTest, UnprivilegedInvalidGid) {
+  if (LIBC_NAMESPACE::getgid() == 0)
+    return;
+  ASSERT_THAT(LIBC_NAMESPACE::setegid(static_cast<gid_t>(-2)),
+              Fails(any_of(EINVAL, EPERM)));
+}
diff --git a/libc/test/src/unistd/seteuid_test.cpp b/libc/test/src/unistd/seteuid_test.cpp
new file mode 100644
index 00000000000000..c9dcd7f729b96b
--- /dev/null
+++ b/libc/test/src/unistd/seteuid_test.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for seteuid.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "src/unistd/geteuid.h"
+#include "src/unistd/getuid.h"
+#include "src/unistd/seteuid.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+using LlvmLibcSetEUidTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcSetEUidTest, SetCurrentEUid) {
+  // Setting the effective UID to the current effective UID should succeed.
+  ASSERT_THAT(LIBC_NAMESPACE::seteuid(LIBC_NAMESPACE::geteuid()), Succeeds());
+}
+
+TEST_F(LlvmLibcSetEUidTest, SetCurrentUid) {
+  // Setting the effective UID to the current real UID should succeed.
+  ASSERT_THAT(LIBC_NAMESPACE::seteuid(LIBC_NAMESPACE::getuid()), Succeeds());
+}
+
+TEST_F(LlvmLibcSetEUidTest, UnprivilegedInvalidUid) {
+  if (LIBC_NAMESPACE::getuid() == 0)
+    return;
+  ASSERT_THAT(LIBC_NAMESPACE::seteuid(static_cast<uid_t>(-2)),
+              Fails(any_of(EINVAL, EPERM)));
+}



More information about the libc-commits mailing list