fix uid/gid > 2^31

This commit is contained in:
Todd Lewis 2021-10-25 19:38:10 -04:00
parent 23da4f40ea
commit 401d587d2d
2 changed files with 13 additions and 9 deletions

10
pgrep.c
View File

@ -229,8 +229,12 @@ static int strict_atol (const char *restrict str, long *restrict value)
for ( ; *str; ++str) { for ( ; *str; ++str) {
if (! isdigit (*str)) if (! isdigit (*str))
return (0); return 0;
if (res >= LONG_MAX / 10)
return 0;
res *= 10; res *= 10;
if (res >= LONG_MAX - (*str - '0'))
return 0;
res += *str - '0'; res += *str - '0';
} }
*value = sign * res; *value = sign * res;
@ -305,7 +309,7 @@ static int conv_uid (const char *restrict name, struct el *restrict e)
xwarnx(_("invalid user name: %s"), name); xwarnx(_("invalid user name: %s"), name);
return 0; return 0;
} }
e->num = (int) pwd->pw_uid; e->num = pwd->pw_uid;
return 1; return 1;
} }
@ -322,7 +326,7 @@ static int conv_gid (const char *restrict name, struct el *restrict e)
xwarnx(_("invalid group name: %s"), name); xwarnx(_("invalid group name: %s"), name);
return 0; return 0;
} }
e->num = (int) grp->gr_gid; e->num = grp->gr_gid;
return 1; return 1;
} }

View File

@ -159,12 +159,12 @@ typedef struct proc_t {
session, // stat session id session, // stat session id
nlwp, // stat,status number of threads, or 0 if no clue nlwp, // stat,status number of threads, or 0 if no clue
tgid, // (special) thread group ID, the POSIX PID (see also: tid) tgid, // (special) thread group ID, the POSIX PID (see also: tid)
tty, // stat full device number of controlling terminal tty; // stat full device number of controlling terminal
/* FIXME: int uids & gids should be uid_t or gid_t from pwd.h */ uid_t euid; gid_t egid; // stat(),status effective
euid, egid, // stat(),status effective uid_t ruid; gid_t rgid; // status real
ruid, rgid, // status real uid_t suid; gid_t sgid; // status saved
suid, sgid, // status saved uid_t fuid; gid_t fgid; // status fs (used for file access only)
fuid, fgid, // status fs (used for file access only) int
tpgid, // stat terminal process group id tpgid, // stat terminal process group id
exit_signal, // stat might not be SIGCHLD exit_signal, // stat might not be SIGCHLD
processor; // stat current (or most recent?) CPU processor; // stat current (or most recent?) CPU