zsh-workers
 help / color / mirror / code / Atom feed
* ``mktemp() possibly used unsafely''
@ 1998-05-05  2:31 Timothy J Luoma
  1998-05-05  2:59 ` Geoff Wing
  1998-05-05  5:06 ` Zoltan Hidvegi
  0 siblings, 2 replies; 3+ messages in thread
From: Timothy J Luoma @ 1998-05-05  2:31 UTC (permalink / raw)
  To: zsh-workers


I just compiled 3.05 on a NetBSD 1.3 machine and saw this warning:

utils.o: warning: mktemp() possibly used unsafely, consider using mkstemp ()

What is the danger here?  How do I change to mkstemp ?

TjL




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ``mktemp() possibly used unsafely''
  1998-05-05  2:31 ``mktemp() possibly used unsafely'' Timothy J Luoma
@ 1998-05-05  2:59 ` Geoff Wing
  1998-05-05  5:06 ` Zoltan Hidvegi
  1 sibling, 0 replies; 3+ messages in thread
From: Geoff Wing @ 1998-05-05  2:59 UTC (permalink / raw)
  To: zsh-workers

Timothy J Luoma <luomat+Lists/Zsh/workers@luomat.peak.org> typed:
:I just compiled 3.05 on a NetBSD 1.3 machine and saw this warning:
:utils.o: warning: mktemp() possibly used unsafely, consider using mkstemp ()
:What is the danger here?  How do I change to mkstemp ?

mkstemp() atomically creates the temporary file, whereas when using mktemp()
someone could create a file of the same name between calling mktemp() and
creating that file.

When zsh uses mktemp() it open()s those files with flags O_CREAT and O_EXCL
or runs mkfifo()/mknod() on it, and it's not a problem for us since we
properly check the return values (I believe), so we don't need to change
anything here.
-- 
Geoff Wing   <gcw@pobox.com>            Mobile : 0412 162 441
Work URL: http://www.primenet.com.au/   Ego URL: http://pobox.com/~gcw/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ``mktemp() possibly used unsafely''
  1998-05-05  2:31 ``mktemp() possibly used unsafely'' Timothy J Luoma
  1998-05-05  2:59 ` Geoff Wing
@ 1998-05-05  5:06 ` Zoltan Hidvegi
  1 sibling, 0 replies; 3+ messages in thread
From: Zoltan Hidvegi @ 1998-05-05  5:06 UTC (permalink / raw)
  To: Timothy J Luoma; +Cc: zsh-workers

> utils.o: warning: mktemp() possibly used unsafely, consider using mkstemp ()
> 
> What is the danger here?  How do I change to mkstemp ?

Do not worry, mktemp is just fine if you know how to use it.  It is a
common mistake to use fopen or open with improper flags on the result of
mktemp.  A bad guy can guess the result of mktemp, and may try to create
a symlink with that name to some precious file, like your mailbox or
.rhosts file before your open is executed (but after mktemp has
finished).  Zsh always uses open(name, O_WRONLY | O_CREAT | O_EXCL, 0600)
to open such a file since 2.6-beta14.  Besides zsh also uses mktemp to
create temporary fifos for process substitution in which case mkstemp is
not really appropriate.

Ironically there has been a bug in the GNU libc and derivatives
(i.e. Linux libc 5) which created mkstemp files with 0666 permissions,
which means that mktemp when used properly can be more secure than
mkstemp.

Zoli


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-05-05  5:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-05  2:31 ``mktemp() possibly used unsafely'' Timothy J Luoma
1998-05-05  2:59 ` Geoff Wing
1998-05-05  5:06 ` Zoltan Hidvegi

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).