Bug 23636 - Fix for bug 1190 (introducing sticky EOF) breaks stream concatenation via dup2
Summary: Fix for bug 1190 (introducing sticky EOF) breaks stream concatenation via dup2
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: stdio (show other bugs)
Version: 2.28
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-12 01:33 UTC by Chris Severance
Modified: 2018-09-21 09:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.