From owner-freebsd-audit Thu May 16 7:41:27 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 2049137B419 for ; Thu, 16 May 2002 07:39:06 -0700 (PDT) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id AAA22705; Fri, 17 May 2002 00:32:43 +1000 Date: Fri, 17 May 2002 00:35:07 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Giorgos Keramidas Cc: Mike Makonnen , Subject: Re: RFC: Port of NetBSD cat(1)'s -f option. In-Reply-To: <20020516123835.GA93447@hades.hell.gr> Message-ID: <20020516235833.S933-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, 16 May 2002, Giorgos Keramidas wrote: > On 2002-05-16 17:40, Bruce Evans wrote: > > Using stat() instead of fstat() gives some races. NetBSD reduces the > > races by checking the mode both before and after open(). > > I have the following version of basesrc/bin/cat locally: > $NetBSD: cat.c,v 1.30 2002/05/09 02:13:10 thorpej Exp $ > > This checks only after the open with fstat(). I agree that using > fstat() is better. Thanks for pointing this out ;) Oops, I misread 1.27. It checks only after open() too (deep in fopen() in the cooked case). Problems with open() are limited by using the O_NONBLOCK flag in the -f case, but there can still be problems (open() and/or close() can have side effects), so I think a stat() should be tried first and checked later. > Removed after a comment by Mike Makonnen. > > > - more verbose and bogus handling of the variable 'i'. 'i' is just the > > loop counter for a `for' loop that is obfuscated as a `while' loop. > > I can't think of some way to use `i' differently, without rewriting > the `while' loop as a `for' loop too. Mixing this change with the > addition of -f seemed like wrong to me though. The conversion to a > `for' loop can be done in a separate change, if it's deemed necessary. > > What is it that makes you think the handling of `i' in the added code > is bogus? :-/ The obfuscated `for' loop wasn't too bad when `i' was incremented in one place, but `i' is now incremented in 3 places and commented on in two places. I first noticed the style bug of duplicating the comment. One comment about a simple increment may be justified because the loop is obfuscated, but not two. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message