This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] use mkstemp instead of mktemp.


On Tue, Jul 01, 2003 at 11:39:19PM -0700, Muthukumar Ratty wrote:
> > > > You can't just mechanically replace mktemp() with mkstemp().  They
> > > > have different return values.
> > > >mkstemp() returns the newly opened
> > > > file.
> > >
> > > and also modifies the template properly so I think it should be ok.
> >
> > Note that blindly ignoring the return value of mkstemp() and then using
> > the modified template to open the file will create exactly the same race
> 
> mkstemp actually creates the file. so when we open, it should be
> unique.... am i missing something?

Er, you're both right, BUT.

mkstemp returns a file descriptor (if all is ok).  If you ignore the
return value, you have an fd leak.  Not quite as evil as a race, but
still evil.

AFAICT the file *will* be unique nevertheless.  Is the return value
merely a convenience since libc already has to open the file?

> > condition that mkstemp() was designed to fix!  You'll remove the link
> > time warning, but not fixed the problem the warning was warning about.

Note that for directories, mktemp is not half as dangerous.  The mkdir(2)
call will fail if the temporary directory already exists.  You just need
to *notice* the error!

Anyway, I think there is a patch floating around that adds a 'directory'
parameter to make_tempname.  It then uses mkstemp for for files, and
mktemp for directories.

-- 
   http://voyager.abite.co.za/~berndj/ - at last it even exists!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]