public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12527] New: Off by one bug with ftell() with fmemopen()
@ 2011-03-01 19:59 per.mathisen at gmail dot com
  2011-03-01 20:09 ` [Bug libc/12527] " per.mathisen at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: per.mathisen at gmail dot com @ 2011-03-01 19:59 UTC (permalink / raw)
  To: glibc-bugs

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

           Summary: Off by one bug with ftell() with fmemopen()
           Product: glibc
           Version: 2.12
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: per.mathisen@gmail.com


Created attachment 5269
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5269
Program that fails

The attached tiny program assert fails on ftell(fp) == ftell(fp), which it
seems to me should always work. I only get this problem with file pointers
created with fmemopen and the "r+" mode, and only with sequences of events
similar to those in the attached file. The ftell() seems to always returns 1
less than the actual size when it fails.

There also seems to be an issue with fmemopen() when used with the "r+" mode if
the input buffer is not zero cleared. See comment in attachment.

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
@ 2011-03-01 20:09 ` per.mathisen at gmail dot com
  2011-03-01 20:12 ` per.mathisen at gmail dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: per.mathisen at gmail dot com @ 2011-03-01 20:09 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #1 from Per Inge Mathisen <per.mathisen at gmail dot com> 2011-03-01 20:08:56 UTC ---
Tested on Fedora 13 glibc 2.12.2 (gcc-4.4.5) and Debian eglibc 2.11.2-13. Both
fail.

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
  2011-03-01 20:09 ` [Bug libc/12527] " per.mathisen at gmail dot com
@ 2011-03-01 20:12 ` per.mathisen at gmail dot com
  2011-03-03 11:58 ` schwab@linux-m68k.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: per.mathisen at gmail dot com @ 2011-03-01 20:12 UTC (permalink / raw)
  To: glibc-bugs

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

Per Inge Mathisen <per.mathisen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
               Host|                            |x86_64

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
  2011-03-01 20:09 ` [Bug libc/12527] " per.mathisen at gmail dot com
  2011-03-01 20:12 ` per.mathisen at gmail dot com
@ 2011-03-03 11:58 ` schwab@linux-m68k.org
  2011-03-03 20:17 ` dflahert at us dot ibm.com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: schwab@linux-m68k.org @ 2011-03-03 11:58 UTC (permalink / raw)
  To: glibc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> 2011-03-03 11:57:54 UTC ---
7.19.5.3 The fopen function
6 When a file is opened with update mode ... input shall not be directly
followed by output without an intervening call to a file positioning function,
unless the input operation encounters end-of-file.

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
                   ` (2 preceding siblings ...)
  2011-03-03 11:58 ` schwab@linux-m68k.org
@ 2011-03-03 20:17 ` dflahert at us dot ibm.com
  2011-03-03 21:28 ` per.mathisen at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dflahert at us dot ibm.com @ 2011-03-03 20:17 UTC (permalink / raw)
  To: glibc-bugs

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

Dave Flaherty <dflahert at us dot ibm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dflahert at us dot ibm.com

--- Comment #3 from Dave Flaherty <dflahert at us dot ibm.com> 2011-03-03 20:16:45 UTC ---
The ftell() Open Group Base Specifications Issue 7 doc states ‘ftell() shall
return the current value of the file-position indicator for the stream.’  The
file position indicator is not updated without an intervening call to the
fflush function or to a file positioning function (fseek, fsetpos, or rewind),
or until the buffer is full.

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
                   ` (3 preceding siblings ...)
  2011-03-03 20:17 ` dflahert at us dot ibm.com
@ 2011-03-03 21:28 ` per.mathisen at gmail dot com
  2011-03-06  4:13 ` drepper.fsp at gmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: per.mathisen at gmail dot com @ 2011-03-03 21:28 UTC (permalink / raw)
  To: glibc-bugs

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

Per Inge Mathisen <per.mathisen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |

--- Comment #4 from Per Inge Mathisen <per.mathisen at gmail dot com> 2011-03-03 21:27:53 UTC ---
The glibc documentation says: "As you can see, ‘+’ requests a stream that can
do both input and output. The ISO standard says that when using such a stream,
you must call fflush (see Stream Buffering) or a file positioning function such
as fseek (see File Positioning) when switching from reading to writing or vice
versa. Otherwise, internal buffers might not be emptied properly. The GNU C
library does not have this limitation; you can do arbitrary reading and writing
operations on a stream in whatever order." (12.3 Opening Streams)

So either the documentation or the code is in error here.

(http://www.gnu.org/s/libc/manual/html_node/Opening-Streams.html#Opening-Streams)

About ftell(), it also says: "each time a character is read or written, the
file position is incremented" (11.1.2 File Position), which makes a lot of
sense. Otherwise you have to implement your own code layer above streams just
to count bytes in many cases. Thankfully this does seem to be working fine in
glibc.

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
                   ` (4 preceding siblings ...)
  2011-03-03 21:28 ` per.mathisen at gmail dot com
@ 2011-03-06  4:13 ` drepper.fsp at gmail dot com
  2011-03-07 21:04 ` per.mathisen at gmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-03-06  4:13 UTC (permalink / raw)
  To: glibc-bugs

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

Ulrich Drepper <drepper.fsp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |SUSPENDED

--- Comment #5 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-03-06 04:13:36 UTC ---
(In reply to comment #4)
> So either the documentation or the code is in error here.

If you want to see the documentation changed send a patch.  The code is what
determines the semantics.  That text is for a different implementation.  Your
program is just plain wrong and if you add the fseek in the appropriate place
everything works find.

Suspended until a doc patch is received.

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
                   ` (5 preceding siblings ...)
  2011-03-06  4:13 ` drepper.fsp at gmail dot com
@ 2011-03-07 21:04 ` per.mathisen at gmail dot com
  2011-03-12 21:46 ` per.mathisen at gmail dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: per.mathisen at gmail dot com @ 2011-03-07 21:04 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #6 from Per Inge Mathisen <per.mathisen at gmail dot com> 2011-03-07 21:04:01 UTC ---
Created attachment 5279
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5279
Remove erroneous text from the documentation

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
                   ` (6 preceding siblings ...)
  2011-03-07 21:04 ` per.mathisen at gmail dot com
@ 2011-03-12 21:46 ` per.mathisen at gmail dot com
  2011-05-12  3:45 ` drepper.fsp at gmail dot com
  2014-06-27 13:48 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: per.mathisen at gmail dot com @ 2011-03-12 21:46 UTC (permalink / raw)
  To: glibc-bugs

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

Per Inge Mathisen <per.mathisen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |ASSIGNED

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
                   ` (7 preceding siblings ...)
  2011-03-12 21:46 ` per.mathisen at gmail dot com
@ 2011-05-12  3:45 ` drepper.fsp at gmail dot com
  2014-06-27 13:48 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-05-12  3:45 UTC (permalink / raw)
  To: glibc-bugs

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

Ulrich Drepper <drepper.fsp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #7 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-05-12 03:44:38 UTC ---
I've added the change.

-- 
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] 11+ messages in thread

* [Bug libc/12527] Off by one bug with ftell() with fmemopen()
  2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
                   ` (8 preceding siblings ...)
  2011-05-12  3:45 ` drepper.fsp at gmail dot com
@ 2014-06-27 13:48 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: fweimer at redhat dot com @ 2014-06-27 13:48 UTC (permalink / raw)
  To: glibc-bugs

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

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] 11+ messages in thread

end of thread, other threads:[~2014-06-27 13:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-01 19:59 [Bug libc/12527] New: Off by one bug with ftell() with fmemopen() per.mathisen at gmail dot com
2011-03-01 20:09 ` [Bug libc/12527] " per.mathisen at gmail dot com
2011-03-01 20:12 ` per.mathisen at gmail dot com
2011-03-03 11:58 ` schwab@linux-m68k.org
2011-03-03 20:17 ` dflahert at us dot ibm.com
2011-03-03 21:28 ` per.mathisen at gmail dot com
2011-03-06  4:13 ` drepper.fsp at gmail dot com
2011-03-07 21:04 ` per.mathisen at gmail dot com
2011-03-12 21:46 ` per.mathisen at gmail dot com
2011-05-12  3:45 ` drepper.fsp at gmail dot com
2014-06-27 13:48 ` fweimer at redhat 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).