From 878382facbe5705f4b24530f6786529a26b042f8 Mon Sep 17 00:00:00 2001 From: Brian Feldman Date: Thu, 10 Oct 2002 17:11:20 +0000 Subject: [PATCH] Correct argc verification (don't crash). Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories --- usr.sbin/extattr/rmextattr.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/usr.sbin/extattr/rmextattr.c b/usr.sbin/extattr/rmextattr.c index 40f9e9608a34..13bebc60a2c5 100644 --- a/usr.sbin/extattr/rmextattr.c +++ b/usr.sbin/extattr/rmextattr.c @@ -102,7 +102,8 @@ main(int argc, char *argv[]) char *buf, *visbuf, *p; const char *options, *attrname; - int buflen, visbuflen, ch, error, i, arg_counter, attrnamespace; + int buflen, visbuflen, ch, error, i, arg_counter, attrnamespace, + minargc; int flag_force = 0; int flag_nofollow = 0; @@ -119,15 +120,19 @@ main(int argc, char *argv[]) if (!strcmp(p, "getextattr")) { what = EAGET; options = "fhqsx"; + minargc = 3; } else if (!strcmp(p, "setextattr")) { what = EASET; options = "fhq"; + minargc = 4; } else if (!strcmp(p, "rmextattr")) { what = EARM; options = "fhq"; + minargc = 3; } else if (!strcmp(p, "lsextattr")) { what = EALS; options = "fhq"; + minargc = 2; } else { usage(); } @@ -158,7 +163,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc < 2) + if (argc < minargc) usage(); error = extattr_string_to_namespace(argv[0], &attrnamespace);