Public bug reported:

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.

** Affects: glibc (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "bugInLinux.tar.bz2"
   
https://bugs.launchpad.net/bugs/1660728/+attachment/4811456/+files/bugInLinux.tar.bz2

** Package changed: ubuntu => glibc (Ubuntu)

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1660728

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

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1660728/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to