aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/chkgrp
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2005-08-25 17:01:06 +0000
committerColin Percival <cperciva@FreeBSD.org>2005-08-25 17:01:06 +0000
commita2c16fbcd05e3b6aae06ec63d49418627ad9ccac (patch)
tree934fa90619ceb6fd5a4bc7cdf4330efb3f8c698d /usr.sbin/chkgrp
parentf41317de6640f13e93d1271bd9dd871800ece5d0 (diff)
downloadsrc-a2c16fbcd05e3b6aae06ec63d49418627ad9ccac.tar.gz
src-a2c16fbcd05e3b6aae06ec63d49418627ad9ccac.zip
Fix a bug introduced in revision 1.9 which causes chkgrp to coredump on
certain corrupt files. Submitted by: liamfoy@dragonflybsd.org Reported by: Nikolay Kalev, via freebsd-current MFC after: 3 days
Notes
Notes: svn path=/head/; revision=149463
Diffstat (limited to 'usr.sbin/chkgrp')
-rw-r--r--usr.sbin/chkgrp/chkgrp.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.sbin/chkgrp/chkgrp.c b/usr.sbin/chkgrp/chkgrp.c
index 635ec8fc9865..eca26afa60f2 100644
--- a/usr.sbin/chkgrp/chkgrp.c
+++ b/usr.sbin/chkgrp/chkgrp.c
@@ -36,6 +36,8 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <sysexits.h>
+static char empty[] = { 0 };
+
static void
usage(void)
{
@@ -105,6 +107,13 @@ main(int argc, char *argv[])
line[i++] = 0;
}
+ if (k < 4) {
+ warnx("%s: line %d: missing field(s)", gfn, n);
+ for ( ; k < 4; k++)
+ f[k] = empty;
+ e++;
+ }
+
for (cp = f[0] ; *cp ; cp++) {
if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-' &&
(cp > f[0] || *cp != '+')) {
@@ -121,11 +130,6 @@ main(int argc, char *argv[])
}
}
- if (k < 4) {
- warnx("%s: line %d: missing field(s)", gfn, n);
- e++;
- }
-
/* check if fourth field ended with a colon */
if (i < len) {
warnx("%s: line %d: too many fields", gfn, n);