diff options
author | Eric Blake <eblake@redhat.com> | 2011-06-29 15:46:50 -0600 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2011-06-29 16:04:56 -0600 |
commit | 3dbe75e4eb0623e54141a53aac7bb71d602e4332 (patch) | |
tree | 348381d47855af4158a39a60c5009ba387709ec9 /doc/glibc-functions/pipe2.texi | |
parent | 0f247f994ecf88c40563c2d264536a1aa7634b33 (diff) | |
download | gnulib-3dbe75e4eb0623e54141a53aac7bb71d602e4332.tar.gz |
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>
Diffstat (limited to 'doc/glibc-functions/pipe2.texi')
-rw-r--r-- | doc/glibc-functions/pipe2.texi | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/doc/glibc-functions/pipe2.texi b/doc/glibc-functions/pipe2.texi index 5721ae9b98..4bc1cb6eb6 100644 --- a/doc/glibc-functions/pipe2.texi +++ b/doc/glibc-functions/pipe2.texi @@ -14,6 +14,10 @@ IRIX 6.5, OSF/1 5.1, Solaris 11 2010-11, Cygwin 1.7.1, mingw, Interix 3.5, BeOS. Portability problems not fixed by Gnulib: @itemize +@item +This function crashes rather than failing with @code{EMFILE} if no +resources are left on some platforms: +Cygwin 1.7.9. @end itemize Note: This function portably supports the @code{O_NONBLOCK} flag only if the |