Blame SOURCES/pgrep-uid-gid-overflow-backport.patch

340a94
From 401d587d2deb78adcf62517654f955a24b2d537d Mon Sep 17 00:00:00 2001
340a94
From: Todd Lewis <todd_lewis@unc.edu>
340a94
Date: Mon, 25 Oct 2021 19:38:10 -0400
340a94
Subject: [PATCH] fix uid/gid > 2^31
340a94
340a94
---
340a94
 pgrep.c         | 10 +++++++---
340a94
 proc/readproc.h | 12 ++++++------
340a94
 2 files changed, 13 insertions(+), 9 deletions(-)
340a94
340a94
diff --git a/pgrep.c b/pgrep.c
340a94
index 1905cd1d..7d731620 100644
340a94
--- a/pgrep.c
340a94
+++ b/pgrep.c
340a94
@@ -229,8 +229,12 @@ static int strict_atol (const char *restrict str, long *restrict value)
340a94
 
340a94
 	for ( ; *str; ++str) {
340a94
 		if (! isdigit (*str))
340a94
-			return (0);
340a94
+			return 0;
340a94
+		if (res >= LONG_MAX / 10)
340a94
+			return 0;
340a94
 		res *= 10;
340a94
+		if (res >= LONG_MAX - (*str - '0'))
340a94
+			return 0;
340a94
 		res += *str - '0';
340a94
 	}
340a94
 	*value = sign * res;
340a94
@@ -305,7 +309,7 @@ static int conv_uid (const char *restrict name, struct el *restrict e)
340a94
 		xwarnx(_("invalid user name: %s"), name);
340a94
 		return 0;
340a94
 	}
340a94
-	e->num = (int) pwd->pw_uid;
340a94
+	e->num = pwd->pw_uid;
340a94
 	return 1;
340a94
 }
340a94
 
340a94
@@ -322,7 +326,7 @@ static int conv_gid (const char *restrict name, struct el *restrict e)
340a94
 		xwarnx(_("invalid group name: %s"), name);
340a94
 		return 0;
340a94
 	}
340a94
-	e->num = (int) grp->gr_gid;
340a94
+	e->num = grp->gr_gid;
340a94
 	return 1;
340a94
 }
340a94
 
340a94
diff --git a/proc/readproc.h b/proc/readproc.h
340a94
index 7905ea99..8d9ae392 100644
340a94
--- a/proc/readproc.h
340a94
+++ b/proc/readproc.h
340a94
@@ -159,12 +159,12 @@ typedef struct proc_t {
340a94
 	session,	// stat            session id
340a94
 	nlwp,		// stat,status     number of threads, or 0 if no clue
340a94
 	tgid,		// (special)       thread group ID, the POSIX PID (see also: tid)
340a94
-	tty,		// stat            full device number of controlling terminal
340a94
-	/* FIXME: int uids & gids should be uid_t or gid_t from pwd.h */
340a94
-        euid, egid,     // stat(),status   effective
340a94
-        ruid, rgid,     // status          real
340a94
-        suid, sgid,     // status          saved
340a94
-        fuid, fgid,     // status          fs (used for file access only)
340a94
+	tty;		// stat            full device number of controlling terminal
340a94
+    uid_t euid; gid_t egid; // stat(),status effective
340a94
+    uid_t ruid; gid_t rgid; // status        real
340a94
+    uid_t suid; gid_t sgid; // status        saved
340a94
+    uid_t fuid; gid_t fgid; // status        fs (used for file access only)
340a94
+    int
340a94
 	tpgid,		// stat            terminal process group id
340a94
 	exit_signal,	// stat            might not be SIGCHLD
340a94
 	processor;      // stat            current (or most recent?) CPU
340a94
-- 
340a94
GitLab
340a94