From b672357b4a17ff47c77d84118511726a1ee49536 Mon Sep 17 00:00:00 2001 From: Paul Richards Date: Thu, 9 Mar 2000 18:11:16 +0000 Subject: 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) --- libc/gen/pw_scan.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'libc') diff --git a/libc/gen/pw_scan.c b/libc/gen/pw_scan.c index 849effa..d0fb5f1 100644 --- a/libc/gen/pw_scan.c +++ b/libc/gen/pw_scan.c @@ -47,6 +47,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -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; -- cgit v1.2.3-56-ge451