Bug 23636

Summary: Fix for bug 1190 (introducing sticky EOF) breaks stream concatenation via dup2
Product: glibc Reporter: Chris Severance <sourceware.severach>
Component: stdioAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal CC: fweimer
Priority: P2 Flags: fweimer: security-
Version: 2.28   
Target Milestone: ---   
See Also: https://sourceware.org/bugzilla/show_bug.cgi?id=1190
https://github.com/OpenPrinting/cups-filters/issues/58
https://github.com/apple/cups/issues/5396
https://bugzilla.redhat.com/show_bug.cgi?id=1628255
Host: Target:
Build: Last reconfirmed:

Description Chris Severance 2018-09-12 01:33:09 UTC
https://github.com/apple/cups/issues/5396
https://github.com/OpenPrinting/cups-filters/issues/58

File I/O seems to be fine with the patch but pipes as set up by CUPS are not.

We have printers that won't print and a test program that doesn't produce the expected output.
Comment 1 Florian Weimer 2018-09-12 08:47:22 UTC
While double-checking whether we reset _IO_EOF_SEEN in the required places, I found this:

  fp->_IO_read_end += count;
  if (count == 0)
    {
      /* If a stream is read to EOF, the calling application may switch active
	 handles.  As a result, our offset cache would no longer be valid, so
	 unset it.  */
      fp->_offset = _IO_pos_BAD;
      return EOF;
    }

So there was once an expectation that you replace the underlying descriptor (with dup2) after reaching EOF, and this is what cups-filters is doing.  Unfortunately, this extension breaks POSIX compliance in other cases (bug 1190).
Comment 2 Florian Weimer 2018-09-12 11:56:52 UTC
More concretely: My concern is that as the source comment above implies, we used to support concatenating multiple files (or pipes) into the same stdio stream using dup2, as an extension over POSIX.  The fix for bug 1190 removed that extension, breaking existing software.
Comment 3 Florian Weimer 2018-09-21 09:51:31 UTC
Mailing list discussion:

https://sourceware.org/ml/libc-alpha/2018-09/msg00235.html

Consensus seems to be that glibc should not change.