public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/16605] New: Invalid caching of file position in stdio streams
@ 2014-02-19  5:47 bugdal at aerifal dot cx
  2014-02-19  6:01 ` [Bug stdio/16605] " bugdal at aerifal dot cx
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bugdal at aerifal dot cx @ 2014-02-19  5:47 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 16605
           Summary: Invalid caching of file position in stdio streams
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: bugdal at aerifal dot cx

Test case:

#include <stdio.h>
#include <unistd.h>

int main()
{
    FILE *f = tmpfile();
    printf("%ld\n", ftell(f));
    write(fileno(f), "abc", 3);
    printf("%ld\n", ftell(f));
}

Expected output:
0
3

glibc output:
0
0

The issue is that glibc is wrongly caching the file position when it does not
have any guarantee that the stdio FILE stream is or will remain the "active
handle" for the open file description (see POSIX XSH 2.5.1 Interaction of File
Descriptors and Standard I/O Streams). While the exact semantics for active
handle are complex (read the cited text), the basic situation is that you can
only guarantee that the FILE remains the active handle once you've started
reading from or writing to it, and up until an operation that allows the
application to switch to a different active handle (a successful seek, explicit
flush, newline-caused flush on line-buffered stream, reaching eof reading,
etc.).

Note that the test case above only shows the issue for writing, but as far as I
can tell it applies equally to reading, and applies to all possible open modes
(read/write/update/append/etc.). I used tmpfile() for convenience but the same
should work with fopen or fdopen.

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


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

* [Bug stdio/16605] Invalid caching of file position in stdio streams
  2014-02-19  5:47 [Bug stdio/16605] New: Invalid caching of file position in stdio streams bugdal at aerifal dot cx
@ 2014-02-19  6:01 ` bugdal at aerifal dot cx
  2014-02-21  4:43 ` siddhesh at redhat dot com
  2014-06-13  8:13 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: bugdal at aerifal dot cx @ 2014-02-19  6:01 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #1 from Rich Felker <bugdal at aerifal dot cx> ---
One thing I misstated: a successful seek does not permit changing the active
handle, so it seems to be valid to keep the cached offset across fseek/fseeko
calls.

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


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

* [Bug stdio/16605] Invalid caching of file position in stdio streams
  2014-02-19  5:47 [Bug stdio/16605] New: Invalid caching of file position in stdio streams bugdal at aerifal dot cx
  2014-02-19  6:01 ` [Bug stdio/16605] " bugdal at aerifal dot cx
@ 2014-02-21  4:43 ` siddhesh at redhat dot com
  2014-06-13  8:13 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: siddhesh at redhat dot com @ 2014-02-21  4:43 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |siddhesh at redhat dot com
         Resolution|---                         |DUPLICATE

--- Comment #2 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
As discussed on list, this is a variant of bug 16532.

*** This bug has been marked as a duplicate of bug 16532 ***

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


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

* [Bug stdio/16605] Invalid caching of file position in stdio streams
  2014-02-19  5:47 [Bug stdio/16605] New: Invalid caching of file position in stdio streams bugdal at aerifal dot cx
  2014-02-19  6:01 ` [Bug stdio/16605] " bugdal at aerifal dot cx
  2014-02-21  4:43 ` siddhesh at redhat dot com
@ 2014-06-13  8:13 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13  8:13 UTC (permalink / raw)
  To: glibc-bugs

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

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-19  5:47 [Bug stdio/16605] New: Invalid caching of file position in stdio streams bugdal at aerifal dot cx
2014-02-19  6:01 ` [Bug stdio/16605] " bugdal at aerifal dot cx
2014-02-21  4:43 ` siddhesh at redhat dot com
2014-06-13  8:13 ` 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).