This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug stdio/15589] freopen would close oldfd even though oldfd is same as newfd


https://sourceware.org/bugzilla/show_bug.cgi?id=15589

--- Comment #11 from Florian Weimer <fweimer at redhat dot com> ---
(In reply to Paul Eggert from comment #10)
> The usage that caused the bug is something like this, in a program that
> accepts a single arg FILE that may be "-" to denote standard input:
> 
>    if (strcmp (file, "-") != 0 && !freopen (file, "r", stdin))
>       error (EXIT_FAILURE, errno, file);

This looks far more reasonable.

> Here any error due to fd 0 being closed is irrelevant, as it's the first
> time the program has accessed stdin. This is a typical use case for freopen,
> and to some extent it's the reason freopen exists at all.

On the other hand, POSIX is quite clear that calling execve with the descriptor
0 not open for reading and 1/2 not open for writing is undefined.  If this
happens as the result of a shell command, it suggests a shell bug to me.

We could work around it in glibc by associating descriptors 0/1/2 with
/dev/null unconditionally, a not just for SUID programs, but this may impact
backwards compatibility for programs which never plan to use the standard
descriptors in the intended way.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]