exit() doesn't close stdin when it's a file

Bug #1660728 reported by J P
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
New
Undecided
Unassigned

Bug Description

There's a bug in the exit() standard library call when stdin is a file on disk (rather than a pipe or a tty). When exit() is called by a child process, stdin is not properly closed, which results in it being extended in the main process. In the case that the main process repeatedly spawns child processes in a loop that depends on EOF for termination, this results in an infinite loop.

I've attached a simple program to reproduce the bug. The README in the archive contains more details. Running
$ ./buginlinux < test.in
produces the bug, but running,
$ cat test.in | ./buginlinux
does not produce the bug (thus demonstrating that pipes as stdin are fine, but files as stdin are broken).

There's also a program in the archive with a workaround in it. This workaround functions by calling fclose(stdin) right before calling exit(0). This solves the problem and also proves the presence of a bug, since, as stated in exit(3): "All open stdio(3) streams are flushed and closed" when exit is called, so there should be the exact same behavior with or without the fclose call, but evidently there is not.

I strongly suspect that this is a glibc bug but can't file a bug report directly there because I can't build the latest version of glibc.

Revision history for this message
J P (jepugs) wrote :
affects: ubuntu → glibc (Ubuntu)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.