Index: usr.sbin/chown/chown.c =================================================================== --- usr.sbin/chown/chown.c +++ usr.sbin/chown/chown.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,7 @@ static void a_gid(const char *); static void a_uid(const char *); static void chownerr(const char *); -static uid_t id(const char *, const char *); +static id_t id(const char *, const char *); static void usage(void); static void print_info(const FTSENT *, int); @@ -243,19 +244,16 @@ uid = ((pw = getpwnam(s)) != NULL) ? pw->pw_uid : id(s, "user"); } -static uid_t +static id_t id(const char *name, const char *type) { - uid_t val; + unsigned long val; char *ep; - /* - * XXX - * We know that uid_t's and gid_t's are unsigned longs. - */ errno = 0; val = strtoul(name, &ep, 10); - if (errno || *ep != '\0') + _Static_assert(UID_MAX == GID_MAX, "UID and GID MAXes differ"); + if (errno || *ep != '\0' || (val > UID_MAX)) errx(1, "%s: illegal %s name", name, type); return (val); }