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