* PATCH: 4.1.0: mkstemp
@ 2001-06-15 23:14 Peter Stephenson
2001-06-15 23:56 ` Wayne Davison
0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2001-06-15 23:14 UTC (permalink / raw)
To: Zsh hackers list
gcc has taken to complaining about using mktemp() instead of mkstemp().
Index: zshconfig.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/zshconfig.ac,v
retrieving revision 1.5
diff -u -r1.5 zshconfig.ac
--- zshconfig.ac 2001/06/08 18:34:53 1.5
+++ zshconfig.ac 2001/06/15 22:10:13
@@ -915,7 +915,7 @@
readlink faccessx fchdir ftruncate \
fstat lstat lchown \
fseeko ftello \
- mkfifo _mktemp \
+ mkfifo _mktemp mkstemp \
waitpid wait3 \
sigaction sigblock sighold sigrelse sigsetmask sigprocmask \
killpg setpgid setpgrp tcsetpgrp tcgetattr nice \
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.33
diff -u -r1.33 utils.c
--- Src/utils.c 2001/06/09 18:06:32 1.33
+++ Src/utils.c 2001/06/15 22:10:21
@@ -1101,11 +1101,14 @@
if (!(s = getsparam("TMPPREFIX")))
s = DEFAULT_TMPPREFIX;
+#ifdef HAVE_MKSTEMP
+ ret = ((char *) mkstemp(dyncat(unmeta(s), "XXXXXX")));
#ifdef HAVE__MKTEMP
/* Zsh uses mktemp() safely, so silence the warnings */
ret = ((char *) _mktemp(dyncat(unmeta(s), "XXXXXX")));
#else
ret = ((char *) mktemp(dyncat(unmeta(s), "XXXXXX")));
+#endif
#endif
unqueue_signals();
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: 4.1.0: mkstemp
2001-06-15 23:14 PATCH: 4.1.0: mkstemp Peter Stephenson
@ 2001-06-15 23:56 ` Wayne Davison
2001-06-16 3:07 ` Bart Schaefer
2001-06-16 6:48 ` Geoff Wing
0 siblings, 2 replies; 5+ messages in thread
From: Wayne Davison @ 2001-06-15 23:56 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh hackers list
On Sat, 16 Jun 2001, Peter Stephenson wrote:
> gcc has taken to complaining about using mktemp() instead of mkstemp().
Since mkstemp() returns a file handle, not a file name, I reverted the
code in util.c back to how it was.
..wayne..
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: 4.1.0: mkstemp
2001-06-15 23:56 ` Wayne Davison
@ 2001-06-16 3:07 ` Bart Schaefer
2001-06-16 6:24 ` Wayne Davison
2001-06-16 6:48 ` Geoff Wing
1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2001-06-16 3:07 UTC (permalink / raw)
To: Wayne Davison, Peter Stephenson; +Cc: Zsh hackers list
On Jun 15, 4:56pm, Wayne Davison wrote:
} Subject: Re: PATCH: 4.1.0: mkstemp
}
} On Sat, 16 Jun 2001, Peter Stephenson wrote:
} > gcc has taken to complaining about using mktemp() instead of mkstemp().
}
} Since mkstemp() returns a file handle, not a file name, I reverted the
} code in util.c back to how it was.
You should have made a ChangeLog entry, or deleted PWS's ...
We could, of course, do this:
#ifdef HAVE_MKSTEMP
if (close(mkstemp(ret = dyncat(unmeta(s), "XXXXXX"))) < 0 ||
unlink(ret) < 0)
ret = NULL;
#else
...
strictly for purposes of silencing silly warnings. However, it is the
case that zsh always uses mktemp() safely -- it always opens the file
with O_CREAT|O_EXCL after generating the name, so it'll simply fail if
someone else manages to create the name first; zsh can't be duped into
using a file owned by someone else as long as $TMPPREFIX does not refer
to an NFS filesystem (in which case even mkstemp() is not safe, as far
as I can tell).
I suppose one could conceivably use this behavior to do a crude DoS attack
on a zsh user on systems where mktemp() is predictable. Of course, the
create/unlink trick above makes it possible to actually watch for the name
to appear and then re-create it immediately after it vanishes, which is
probably worse than if it were never created in the first place.
I was just checking through the code that uses gettempname(), and there
is only one instance where we absolutely couldn't use mkstemp() instead:
The case of wanting to create a temporary FIFO. There we'd have to do
an unlink() before the mkfifo(), which makes mkstemp() no improvement.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: 4.1.0: mkstemp
2001-06-16 3:07 ` Bart Schaefer
@ 2001-06-16 6:24 ` Wayne Davison
0 siblings, 0 replies; 5+ messages in thread
From: Wayne Davison @ 2001-06-16 6:24 UTC (permalink / raw)
To: Zsh hackers list
On Sat, 16 Jun 2001, Bart Schaefer wrote:
> You should have made a ChangeLog entry, or deleted PWS's ...
Thanks, I got distracted there for a moment. I've committed my
ChangeLog entry.
> if (close(mkstemp(ret = dyncat(unmeta(s), "XXXXXX"))) < 0 ||
> unlink(ret) < 0)
Oooh, slimey! That would sure silence the (dubious) warning, but I
would hate the extra open/close/unlink. Perhaps we should just link in
a work-alike mktemp() function that doesn't generate a warning?
..wayne..
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: 4.1.0: mkstemp
2001-06-15 23:56 ` Wayne Davison
2001-06-16 3:07 ` Bart Schaefer
@ 2001-06-16 6:48 ` Geoff Wing
1 sibling, 0 replies; 5+ messages in thread
From: Geoff Wing @ 2001-06-16 6:48 UTC (permalink / raw)
To: zsh-workers
Wayne Davison <wayned@users.sourceforge.net> typed:
: On Sat, 16 Jun 2001, Peter Stephenson wrote:
:> gcc has taken to complaining about using mktemp() instead of mkstemp().
: Since mkstemp() returns a file handle, not a file name, I reverted the
: code in util.c back to how it was.
Of course, given it's just about certain to be immediately clobbered by
the following lines . . . .
Peter did that around 10pm on a Friday night; he must have just come
back from the pub. Oops :-)
....
+#ifdef HAVE_MKSTEMP
+ ret = ((char *) mkstemp(dyncat(unmeta(s), "XXXXXX")));
#ifdef HAVE__MKTEMP
/* Zsh uses mktemp() safely, so silence the warnings */
ret = ((char *) _mktemp(dyncat(unmeta(s), "XXXXXX")));
#else
ret = ((char *) mktemp(dyncat(unmeta(s), "XXXXXX")));
+#endif
#endif
unqueue_signals();
....
Regards,
--
Geoff Wing : <gcw@pobox.com>
Rxvt Stuff : <gcw@rxvt.org>
Zsh Stuff : <gcw@zsh.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-06-16 6:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-15 23:14 PATCH: 4.1.0: mkstemp Peter Stephenson
2001-06-15 23:56 ` Wayne Davison
2001-06-16 3:07 ` Bart Schaefer
2001-06-16 6:24 ` Wayne Davison
2001-06-16 6:48 ` Geoff Wing
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).