From owner-cvs-all Tue Oct 20 08:32:29 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA26386 for cvs-all-outgoing; Tue, 20 Oct 1998 08:32:29 -0700 (PDT) (envelope-from owner-cvs-all@FreeBSD.ORG) Received: from spinner.netplex.com.au (spinner.netplex.com.au [202.12.86.3]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA26267; Tue, 20 Oct 1998 08:31:59 -0700 (PDT) (envelope-from peter@netplex.com.au) Received: from spinner.netplex.com.au (localhost [127.0.0.1]) by spinner.netplex.com.au (8.9.1/8.9.1/Spinner) with ESMTP id XAA12150; Tue, 20 Oct 1998 23:30:10 +0800 (WST) (envelope-from peter@spinner.netplex.com.au) Message-Id: <199810201530.XAA12150@spinner.netplex.com.au> X-Mailer: exmh version 2.0.2 2/24/98 To: Bruce Evans cc: cvs-all@FreeBSD.ORG, cvs-committers@FreeBSD.ORG Subject: Re: cvs commit: src/lib/libc/stdio mktemp.c In-reply-to: Your message of "Wed, 21 Oct 1998 00:59:40 +1000." <199810201459.AAA10106@godzilla.zeta.org.au> Date: Tue, 20 Oct 1998 23:30:09 +0800 From: Peter Wemm Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk Bruce Evans wrote: > >I'm not sure how to best fix it that is *safe*. > > Yes, any change breaks: > > /* > * Prevent even ourself from easily accessing the tmp file except > * via the fd returned by mkstemp(). Dont ask why :-). > */ > umask(0777); > fd = mkstemp(foo); man mkstemp: The mkstemp() function makes the same replacement to the template and creates the template file, mode 0600, returning a file descriptor opened ^^^^ for reading and writing. This avoids the race between testing for a file's existence and opening it for use. A specfic mode is specified, your example is broken, especially on NFS. The way to implement what you want is: fd = mkstemp(foo); unlink(foo); or, if you want a FILE * in the end, use "fp = tmpfile();" > >Leaving it failing due to the umask preventing it from opening the file it > >just created isn't ideal because the mk*temp() function has *failed* and > >yet it still created the file. I don't believe it's safe to > > mk*temp() hasn't failed. It returns a r/w file descriptor for a file > with mod 0000. vi has problems when it closes this fd and attempts to > reopen it. Yes, you are right, nvi is going gaga. However, mkstemp() is still broken, it does not behave as specified. This interface is not one we "own" and we cannot change it. > Bruce Cheers, -Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message