From 27f504883547502b1f5e4e389edd7f26e3ab246f Mon Sep 17 00:00:00 2001
From: Masakazu Kitajo <maskit@apache.org>
Date: Tue, 12 Nov 2024 11:13:59 -0700
Subject: [PATCH] Fix unchecked return value of initgroups() (#11855)

Origin: https://github.com/apache/trafficserver/commit/27f504883547502b1f5e4e389edd7f26e3ab246f

* Fix unchecked return value of initgroups()

Signed-off-by: Jeffrey Bencteux <jeffbencteux@gmail.com>

* clang-format

---------

Signed-off-by: Jeffrey Bencteux <jeffbencteux@gmail.com>
Co-authored-by: Jeffrey Bencteux <jeffbencteux@gmail.com>
(cherry picked from commit ae638096e259121d92d46a9f57026a5ff5bc328b)
---
 src/tscore/ink_cap.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/tscore/ink_cap.cc b/src/tscore/ink_cap.cc
index b4f0ecace5d..8a95d4b1329 100644
--- a/src/tscore/ink_cap.cc
+++ b/src/tscore/ink_cap.cc
@@ -160,7 +160,9 @@ impersonate(const struct passwd *pwd, ImpersonationLevel level)
 #endif
 
   // Always repopulate the supplementary group list for the new user.
-  initgroups(pwd->pw_name, pwd->pw_gid);
+  if (initgroups(pwd->pw_name, pwd->pw_gid) != 0) {
+    Fatal("switching to user %s, failed to initialize supplementary groups ID %ld", pwd->pw_name, (long)pwd->pw_gid);
+  }
 
   switch (level) {
   case IMPERSONATE_PERMANENT:
