From 84a8b19d55a789fa90e919f970e259cbfa7786ed Mon Sep 17 00:00:00 2001 From: eadler Date: Thu, 15 Nov 2012 15:06:03 +0000 Subject: Check the range of the gid Approved by: cperciva MFC after: 1 week --- usr.sbin/chkgrp/chkgrp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'usr.sbin/chkgrp') diff --git a/usr.sbin/chkgrp/chkgrp.c b/usr.sbin/chkgrp/chkgrp.c index ac40ed5..2dd41a8 100644 --- a/usr.sbin/chkgrp/chkgrp.c +++ b/usr.sbin/chkgrp/chkgrp.c @@ -30,7 +30,10 @@ __FBSDID("$FreeBSD$"); #include +#include #include +#include +#include #include #include #include @@ -150,6 +153,18 @@ main(int argc, char *argv[]) warnx("%s: line %d: GID is not numeric", gfn, n); e++; } + + /* check the range of the group id */ + errno = 0; + unsigned long groupid = strtoul(f[2], NULL, 10); + if (errno != 0) { + warnx("%s: line %d: strtoul failed", gfn, n); + } + else if (groupid > GID_MAX) { + warnx("%s: line %d: group id is too large (> %ju)", + gfn, n, (uintmax_t)GID_MAX); + e++; + } #if 0 /* entry is correct, so print it */ -- cgit v1.1