diff options
author | paul <paul@FreeBSD.org> | 2000-03-09 18:11:16 +0000 |
---|---|---|
committer | paul <paul@FreeBSD.org> | 2000-03-09 18:11:16 +0000 |
commit | 62f215a16f0bb6bee8de286f75380af61a8981bb (patch) | |
tree | 1a587389adcb07ae1838b9cead700288d5354a5d /lib/libc | |
parent | 8e3795df0fb6cdfc739049fb0fcab846da61d760 (diff) | |
download | FreeBSD-src-62f215a16f0bb6bee8de286f75380af61a8981bb.zip FreeBSD-src-62f215a16f0bb6bee8de286f75380af61a8981bb.tar.gz |
Fix various unsigned vs signed errors that caused problems with uids
and gids bigger than 16 bits. Added checks for uids and gids that are
bigger than 32 bits.
Approved by: jkh (partly, this fix is bigger than I first intended)
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/pw_scan.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/libc/gen/pw_scan.c b/lib/libc/gen/pw_scan.c index 849effa..d0fb5f1 100644 --- a/lib/libc/gen/pw_scan.c +++ b/lib/libc/gen/pw_scan.c @@ -47,6 +47,7 @@ static const char rcsid[] = #include <sys/param.h> #include <err.h> +#include <errno.h> #include <fcntl.h> #include <pwd.h> #include <stdio.h> @@ -72,7 +73,7 @@ pw_scan(bp, pw) char *bp; struct passwd *pw; { - long id; + uid_t id; int root; char *p, *sh; @@ -100,13 +101,17 @@ pw_scan(bp, pw) return (0); } } - id = atol(p); + id = strtoul(p, (char **)NULL, 10); + if (errno == ERANGE) { + warnx("%s > max uid value (%u)", p, ULONG_MAX); + return (0); + } if (root && id) { warnx("root uid should be 0"); return (0); } if (pw_big_ids_warning && id > USHRT_MAX) { - warnx("%s > max uid value (%u)", p, USHRT_MAX); + warnx("%s > recommended max uid value (%u)", p, USHRT_MAX); /*return (0);*/ /* THIS SHOULD NOT BE FATAL! */ } pw->pw_uid = id; @@ -114,9 +119,13 @@ pw_scan(bp, pw) if (!(p = strsep(&bp, ":"))) /* gid */ goto fmt; if(p[0]) pw->pw_fields |= _PWF_GID; - id = atol(p); + id = strtoul(p, (char **)NULL, 10); + if (errno == ERANGE) { + warnx("%s > max gid value (%u)", p, ULONG_MAX); + return (0); + } if (pw_big_ids_warning && id > USHRT_MAX) { - warnx("%s > max gid value (%u)", p, USHRT_MAX); + warnx("%s > recommended max gid value (%u)", p, USHRT_MAX); /* return (0); This should not be fatal! */ } pw->pw_gid = id; |