This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/21398] freopen does not check dup3 return value, and does not return error if dup3 fails (seen when open returns fd 0, and freopen on stdin)
- From: "olson at cumulusnetworks dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 19 Apr 2017 15:38:16 +0000
- Subject: [Bug stdio/21398] freopen does not check dup3 return value, and does not return error if dup3 fails (seen when open returns fd 0, and freopen on stdin)
- Auto-submitted: auto-generated
- References: <bug-21398-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=21398
--- Comment #6 from Dave Olson <olson at cumulusnetworks dot com> ---
It's not trying to use a stream where the underlying fd is closed, it's trying
to create stdin.
Think of processes that are exec'ed without fd 0 open (which is the real test
case, because it's marked close on exec).
What it's trying to do is to establish a stdin for use with functions that
expect to use stdin.
Even if you don't accept that as a valid use case (and I can accept the
argument, even though I don't agree with it), freopen() should be returning an
error, which means it needs to check for dup3 returning errors.
Right now, freopen in this situation returns what appears to be a valid FILE *,
but the requested action on stdin will fail.
So the minimum is to check for dup3() errors, and then return an error from
freopen().
--
You are receiving this mail because:
You are on the CC list for the bug.