bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefined behavior in closeout, aggravated by libsigsegv


From: Eric Blake
Subject: Re: undefined behavior in closeout, aggravated by libsigsegv
Date: Sun, 22 Nov 2009 07:58:45 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Bruno Haible on 11/22/2009 5:32 AM:
> Eric Blake wrote on 2009-07-18:
>> fileno(stdout) == 1 by definition of STDOUT_FILENO, so you don't
>> have to go via fileno (you can directly use fcntl(1,...) to learn whether
>> the fd has been closed).
> 
> But the user might have called freopen (..., stdout). In this case,
> fileno (stdout) will no longer be 1.

That is ONLY possible if both:
stdin was closed
the user is not using freopen_safer

in which case the fd will be 0 instead of 1.  There is no way for
freopen() to ever make fileno(stdout) ever be greater than 1.

> So you actually do have to use
> fileno (stdout) in the patch that you committed on 2009-07-18
> <http://lists.gnu.org/archive/html/bug-gnulib/2009-07/msg00040.html>
> 
> Here is a proposed patch:

I'd rather make the patch conditional on whether freopen_safer is also in use.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksJUaUACgkQ84KuGfSFAYABCQCfQQc1WDE++goK3Ku01QdNXGQo
DDMAnj8tkxZZhFCYtkwF5KH7Vvu80VwO
=bynP
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]