summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorPaul Richards <paul@FreeBSD.org>2000-03-09 18:11:16 +0000
committerPaul Richards <paul@FreeBSD.org>2000-03-09 18:11:16 +0000
commitb672357b4a17ff47c77d84118511726a1ee49536 (patch)
treee25871fe7927afd6962fda4795cf3a6f163ee625 /libc
parent586a773c1341bb9324c93f01d0456bf0bf6fa807 (diff)
downloadpw-darwin-b672357b4a17ff47c77d84118511726a1ee49536.tar.gz
pw-darwin-b672357b4a17ff47c77d84118511726a1ee49536.tar.zst
pw-darwin-b672357b4a17ff47c77d84118511726a1ee49536.zip
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 'libc')
-rw-r--r--libc/gen/pw_scan.c19
1 files changed, 14 insertions, 5 deletions
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 <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;