Re: RFC: Port of NetBSD cat(1)'s -f option.
Bruce Evans <[email protected]>
| Newsgroups | gmane.os.freebsd.devel.audit |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 16 May 2002, Giorgos Keramidas wrote: > On 2002-05-16 17:40, Bruce Evans <[email protected]> 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 [email protected] with "unsubscribe freebsd-audit" in the body of the message