From owner-freebsd-audit@FreeBSD.ORG Wed Oct 22 04:46:59 2003 Return-Path: Delivered-To: freebsd-audit@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E244C16A4B3 for ; Wed, 22 Oct 2003 04:46:59 -0700 (PDT) Received: from heechee.tobez.org (heechee.tobez.org [217.157.39.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id B409C43F93 for ; Wed, 22 Oct 2003 04:46:58 -0700 (PDT) (envelope-from tobez@tobez.org) Received: by heechee.tobez.org (Postfix, from userid 1001) id AA796175CF; Wed, 22 Oct 2003 13:46:56 +0200 (CEST) Date: Wed, 22 Oct 2003 13:46:56 +0200 From: Anton Berezin To: audit@freebsd.org Message-ID: <20031022114656.GB1141@heechee.tobez.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i Subject: simplify mode parsing in chmod(1) X-BeenThere: freebsd-audit@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD Security Audit List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Oct 2003 11:47:00 -0000 Hi, Any objections to this patch (yes, setmode(3) handles octal modes)? Index: chmod.c =================================================================== RCS file: /home/ncvs/src/bin/chmod/chmod.c,v retrieving revision 1.29 diff -u -r1.29 chmod.c --- chmod.c 1 May 2003 16:58:54 -0000 1.29 +++ chmod.c 22 Oct 2003 11:14:49 -0000 @@ -65,16 +65,13 @@ FTS *ftsp; FTSENT *p; mode_t *set; - long val; - int oct; int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval; int vflag; - char *ep, *mode; - mode_t newmode, omode; + char *mode; + mode_t newmode; int (*change_mode)(const char *, mode_t); set = NULL; - omode = 0; Hflag = Lflag = Rflag = fflag = hflag = vflag = 0; while ((ch = getopt(argc, argv, "HLPRXfghorstuvwx")) != -1) switch (ch) { @@ -152,22 +149,8 @@ change_mode = chmod; mode = *argv; - if (*mode >= '0' && *mode <= '7') { - errno = 0; - val = strtol(mode, &ep, 8); - if (val > USHRT_MAX || val < 0) - errno = ERANGE; - if (errno) - err(1, "invalid file mode: %s", mode); - if (*ep) - errx(1, "invalid file mode: %s", mode); - omode = (mode_t)val; - oct = 1; - } else { - if ((set = setmode(mode)) == NULL) - errx(1, "invalid file mode: %s", mode); - oct = 0; - } + if ((set = setmode(mode)) == NULL) + errx(1, "invalid file mode: %s", mode); if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL) err(1, "fts_open"); @@ -200,7 +183,7 @@ default: break; } - newmode = oct ? omode : getmode(set, p->fts_statp->st_mode); + newmode = getmode(set, p->fts_statp->st_mode); if ((newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS)) continue; if ((*change_mode)(p->fts_accpath, newmode) && !fflag) { Cheers, \Anton. -- If I did know the future of Perl, and if I told you, you'd probably run away screaming. -- Larry Wall