summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2004-03-30 04:20:33 +0000
committergad <gad@FreeBSD.org>2004-03-30 04:20:33 +0000
commit283e539306ca4c30e732835b3f0a8e8d815a05fd (patch)
treee493faec4f5b5829b3a964caae5f8e3ec87f3376
parent8e955dcc90e6fcdb18ba53e81e20708338bc789c (diff)
downloadFreeBSD-src-283e539306ca4c30e732835b3f0a8e8d815a05fd.zip
FreeBSD-src-283e539306ca4c30e732835b3f0a8e8d815a05fd.tar.gz
Switch to using strtoul() for parsing a potential UID or GID, which gets
this to correctly handle UID's and GID's larger than 2147483647. Noticed by: bde MFC after: 1 week
-rw-r--r--bin/ps/ps.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index d143697..9dac667 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -629,7 +629,7 @@ addelem_gid(struct listinfo *inf, const char *elem)
struct group *grp;
const char *nameorID;
char *endp;
- intmax_t ltemp;
+ u_long bigtemp;
if (*elem == '\0' || strlen(elem) >= MAXLOGNAME) {
if (*elem == '\0')
@@ -652,10 +652,10 @@ addelem_gid(struct listinfo *inf, const char *elem)
grp = NULL;
nameorID = "named";
errno = 0;
- ltemp = strtol(elem, &endp, 10);
- if (errno == 0 && *endp == '\0' && ltemp >= 0 && ltemp <= GID_MAX) {
+ bigtemp = strtoul(elem, &endp, 10);
+ if (errno == 0 && *endp == '\0' && bigtemp <= GID_MAX) {
nameorID = "name or ID matches";
- grp = getgrgid((gid_t)ltemp);
+ grp = getgrgid((gid_t)bigtemp);
}
if (grp == NULL)
grp = getgrnam(elem);
@@ -742,7 +742,7 @@ addelem_uid(struct listinfo *inf, const char *elem)
{
struct passwd *pwd;
char *endp;
- intmax_t ltemp;
+ u_long bigtemp;
if (*elem == '\0' || strlen(elem) >= MAXLOGNAME) {
if (*elem == '\0')
@@ -756,13 +756,12 @@ addelem_uid(struct listinfo *inf, const char *elem)
pwd = getpwnam(elem);
if (pwd == NULL) {
errno = 0;
- ltemp = strtol(elem, &endp, 10);
- if (errno != 0 || *endp != '\0' || ltemp < 0 ||
- ltemp > UID_MAX)
+ bigtemp = strtoul(elem, &endp, 10);
+ if (errno != 0 || *endp != '\0' || bigtemp > UID_MAX)
warnx("No %s named '%s'", inf->lname, elem);
else {
/* The string is all digits, so it might be a userID. */
- pwd = getpwuid((uid_t)ltemp);
+ pwd = getpwuid((uid_t)bigtemp);
if (pwd == NULL)
warnx("No %s name or ID matches '%s'",
inf->lname, elem);
OpenPOWER on IntegriCloud