Date: Fri, 17 May 2002 00:35:07 +1000 (EST) From: Bruce Evans <bde@zeta.org.au> To: Giorgos Keramidas <keramida@ceid.upatras.gr> Cc: Mike Makonnen <makonnen@pacbell.net>, <freebsd-audit@FreeBSD.org> Subject: Re: RFC: Port of NetBSD cat(1)'s -f option. Message-ID: <20020516235833.S933-100000@gamplex.bde.org> In-Reply-To: <20020516123835.GA93447@hades.hell.gr>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 16 May 2002, Giorgos Keramidas wrote: > On 2002-05-16 17:40, Bruce Evans <bde@zeta.org.au> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020516235833.S933-100000>
