public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/15298] New: open_memstream(): seek-past-end should not change size until write
@ 2013-03-23  4:40 guenther at gmail dot com
  2013-03-23  4:58 ` [Bug libc/15298] " guenther at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: guenther at gmail dot com @ 2013-03-23  4:40 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15298

             Bug #: 15298
           Summary: open_memstream(): seek-past-end should not change size
                    until write
           Product: glibc
           Version: 2.17
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: unassigned@sourceware.org
        ReportedBy: guenther@gmail.com
                CC: drepper.fsp@gmail.com
    Classification: Unclassified


Created attachment 6941
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6941
partial regression test for open_memstream

The IEEE Std 1003.1-2008 (aka POSIX-2008) says this in its description of
open_memstream:
--------
The stream shall maintain a current position in the allocated buffer and a
current buffer length. The position shall be initially set to zero (the start
of the buffer). Each write to the stream shall start at the current position
and move this position by the number of successfully written bytes for
open_memstream() or the number of successfully written wide characters for
open_wmemstream(). The length shall be initially set to zero. If a write moves
the position to a value larger than the current length, the current length
shall be set to this position. In this case a null character for
open_memstream() or a null wide character for open_wmemstream() shall be
appended to the current buffer. For both functions the terminating null is not
included in the calculation of the buffer length.

After a successful fflush() or fclose(), the pointer referenced by bufp shall
contain the address of the buffer, and the variable pointed to by sizep shall
contain the smaller of the current buffer length and the number of bytes for
open_memstream(), or the number of wide characters for open_wmemstream(),
between the beginning of the buffer and the current file position indicator.
--------

So, if you write to the stream, seek past the end, then close it without
writing again, the size location should be set to the end of the furthest write
("smaller of the current buffer length and <...>"), not the seek position.  In
glibc 2.17, it instead returns the seek position.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/15298] open_memstream(): seek-past-end should not change size until write
  2013-03-23  4:40 [Bug libc/15298] New: open_memstream(): seek-past-end should not change size until write guenther at gmail dot com
@ 2013-03-23  4:58 ` guenther at gmail dot com
  2013-03-23  5:34 ` guenther at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: guenther at gmail dot com @ 2013-03-23  4:58 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15298

Philip Guenther <guenther at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |guenther at gmail dot com

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/15298] open_memstream(): seek-past-end should not change size until write
  2013-03-23  4:40 [Bug libc/15298] New: open_memstream(): seek-past-end should not change size until write guenther at gmail dot com
  2013-03-23  4:58 ` [Bug libc/15298] " guenther at gmail dot com
@ 2013-03-23  5:34 ` guenther at gmail dot com
  2014-06-13 18:41 ` fweimer at redhat dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: guenther at gmail dot com @ 2013-03-23  5:34 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=15298

--- Comment #1 from Philip Guenther <guenther at gmail dot com> 2013-03-23 05:33:52 UTC ---
The behavior of fseek(fp, offset, SEEK_END) also seems...odd.  My expectation,
given the wording of the spec, is that it would be relative to the buffer
length (as defined by the spec) but it seems to be relative to something bigger
than that, the actual allocated buffer size, perhaps?  Isn't the stream created
by open_memstream() supposed to behave like an in-memory version of a temp
file, so seeks from SEEK_END should be relative to just past the last written
position?

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libc/15298] open_memstream(): seek-past-end should not change size until write
  2013-03-23  4:40 [Bug libc/15298] New: open_memstream(): seek-past-end should not change size until write guenther at gmail dot com
  2013-03-23  4:58 ` [Bug libc/15298] " guenther at gmail dot com
  2013-03-23  5:34 ` guenther at gmail dot com
@ 2014-06-13 18:41 ` fweimer at redhat dot com
  2015-08-22 20:34 ` [Bug stdio/15298] " jsm28 at gcc dot gnu.org
  2020-06-24 15:57 ` tonyb at cybernetics dot com
  4 siblings, 0 replies; 6+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 18:41 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15298

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug stdio/15298] open_memstream(): seek-past-end should not change size until write
  2013-03-23  4:40 [Bug libc/15298] New: open_memstream(): seek-past-end should not change size until write guenther at gmail dot com
                   ` (2 preceding siblings ...)
  2014-06-13 18:41 ` fweimer at redhat dot com
@ 2015-08-22 20:34 ` jsm28 at gcc dot gnu.org
  2020-06-24 15:57 ` tonyb at cybernetics dot com
  4 siblings, 0 replies; 6+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-08-22 20:34 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15298

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libc                        |stdio

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug stdio/15298] open_memstream(): seek-past-end should not change size until write
  2013-03-23  4:40 [Bug libc/15298] New: open_memstream(): seek-past-end should not change size until write guenther at gmail dot com
                   ` (3 preceding siblings ...)
  2015-08-22 20:34 ` [Bug stdio/15298] " jsm28 at gcc dot gnu.org
@ 2020-06-24 15:57 ` tonyb at cybernetics dot com
  4 siblings, 0 replies; 6+ messages in thread
From: tonyb at cybernetics dot com @ 2020-06-24 15:57 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=15298

Tony Battersby <tonyb at cybernetics dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tonyb at cybernetics dot com

--- Comment #3 from Tony Battersby <tonyb at cybernetics dot com> ---
Created attachment 12657
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12657&action=edit
memstream_open test for fflush vs. fclose

Beginning with glibc 2.25 and up to the current development version, fflush()
vs. fclose() behave differently after a seek + write, so this is still broken. 
The attached test program gives the following output:

The following two lines should be identical:
size 7 strlen 26 buf 'ABCDEFGhijklmnopqrstuvwxyz'
size 7 strlen 7 buf 'ABCDEFG'

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-24 15:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-23  4:40 [Bug libc/15298] New: open_memstream(): seek-past-end should not change size until write guenther at gmail dot com
2013-03-23  4:58 ` [Bug libc/15298] " guenther at gmail dot com
2013-03-23  5:34 ` guenther at gmail dot com
2014-06-13 18:41 ` fweimer at redhat dot com
2015-08-22 20:34 ` [Bug stdio/15298] " jsm28 at gcc dot gnu.org
2020-06-24 15:57 ` tonyb at cybernetics dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).