Mercurial > hg > octave-nkf > gnulib-hg
annotate doc/posix-functions/mkstemp.texi @ 15326:52719068f9c2
pipe, pipe2: don't corrupt fd on error
I noticed a potential subtle double-close bug in libvirt. There,
a common idiom is to initialize an int fd[2]={-1,-1}, then have
multiple error paths goto common cleanup code. In the cleanup
code, the fds are closed if they are not already -1; this works
if the error label is reached before the pipe call, or after
pipe succeeds, but if it was the pipe call itself that jumped
to the error label, then it is relying on failed pipe() not
altering the values already in fd array prior to the failure.
Our pipe2 replacement violated this assumption, and could leave
a non-negative value in the array, which in turn would let
libvirt close an already-closed fd, possibly nuking an unrelated
fd opened by another thread that happened to get the same value.
As a result, I raised a POSIX issue regarding the behavior of
pipe on failure: http://austingroupbugs.net/view.php?id=467
Using that test program, I learned that most systems leave fd
unchanged on error, but that mingw always assigns -1 into the
array. This fixes the mingw pipe() replacement, as well as
the gnulib pipe2() replacement.
I don't know of any race-free way to work around a cygwin crash:
http://cygwin.com/ml/cygwin/2011-06/msg00328.html - we could
always open() and then close() two fds to guess whether two
spare fd still remain before calling pipe(), but that is racy.
* lib/pipe.c (pipe): Leave fd unchanged on error.
* lib/pipe2.c (pipe2): Likewise.
* doc/posix-functions/pipe.texi (pipe): Document cygwin issue.
* doc/glibc-functions/pipe2.texi (pipe2): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Wed, 29 Jun 2011 15:46:50 -0600 |
parents | 1f2629ca413e |
children | f4cc0c20e892 |
rev | line source |
---|---|
9638
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 @node mkstemp |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 @section @code{mkstemp} |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 @findex mkstemp |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
13549
bb0ceefd22dc
avoid some overlong lines from posix urls, etc.
Karl Berry <karl@freefriends.org>
parents:
10876
diff
changeset
|
5 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/mkstemp.html} |
9638
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 Gnulib module: mkstemp |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 Portability problems fixed by Gnulib: |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 @itemize |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 @item |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 This function is missing on some platforms: |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 mingw. |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 @item |
14638
1f2629ca413e
mkstemp: More documentation.
Bruno Haible <bruno@clisp.org>
parents:
14636
diff
changeset
|
15 This function is declared in @code{<unistd.h>} instead of @code{<stdlib.h>} |
1f2629ca413e
mkstemp: More documentation.
Bruno Haible <bruno@clisp.org>
parents:
14636
diff
changeset
|
16 on some platforms: |
1f2629ca413e
mkstemp: More documentation.
Bruno Haible <bruno@clisp.org>
parents:
14636
diff
changeset
|
17 MacOS X 10.3. |
1f2629ca413e
mkstemp: More documentation.
Bruno Haible <bruno@clisp.org>
parents:
14636
diff
changeset
|
18 @item |
9638
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 On some platforms (HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a silly |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 limit that it can create no more than 26 files from a given template. On |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 OSF/1 4.0f, it can create only 32 files per process. |
14627
780006cfcb42
mkstemp: replace if system version uses wrong permissions
Reuben Thomas <rrt@sc3d.org>
parents:
14624
diff
changeset
|
22 @item |
780006cfcb42
mkstemp: replace if system version uses wrong permissions
Reuben Thomas <rrt@sc3d.org>
parents:
14624
diff
changeset
|
23 On some older platforms, @code{mkstemp} can create a world or group |
780006cfcb42
mkstemp: replace if system version uses wrong permissions
Reuben Thomas <rrt@sc3d.org>
parents:
14624
diff
changeset
|
24 writable or readable file, if you haven't set the process umask to |
780006cfcb42
mkstemp: replace if system version uses wrong permissions
Reuben Thomas <rrt@sc3d.org>
parents:
14624
diff
changeset
|
25 077. This is a security risk. |
9638
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 @end itemize |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 Portability problems not fixed by Gnulib: |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 @itemize |
070329237839
Rename two directories: headers -> posix-headers, functions -> posix-functions.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 @end itemize |
14624
e00c934ee25d
mkstemp: mention clean-temp module
Reuben Thomas <rrt@sc3d.org>
parents:
13549
diff
changeset
|
31 |
14636
e38cec555642
clean-temp: Clarify what it does.
Bruno Haible <bruno@clisp.org>
parents:
14627
diff
changeset
|
32 The gnulib module @code{clean-temp} can create temporary files that will not |
e38cec555642
clean-temp: Clarify what it does.
Bruno Haible <bruno@clisp.org>
parents:
14627
diff
changeset
|
33 be left behind after signals such as SIGINT. |