public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
@ 2014-02-06  3:38 ` ppluzhnikov at google dot com
  2014-02-06 22:28 ` ppluzhnikov at google dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppluzhnikov at google dot com @ 2014-02-06  3:38 UTC (permalink / raw)
  To: glibc-bugs

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

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|fdopen(..., "a"); fwrite(); |fdopen(..., "a"); fwrite();
                   |ftell() sequence gives      |ftello() sequence gives
                   |wrong answer                |wrong answer

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


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

* [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer
@ 2014-02-06  3:38 ppluzhnikov at google dot com
  2014-02-06  3:38 ` [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() " ppluzhnikov at google dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ppluzhnikov at google dot com @ 2014-02-06  3:38 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 16532
           Summary: fdopen(..., "a"); fwrite(); ftell() sequence gives
                    wrong answer
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: ppluzhnikov at google dot com

This is a regression from 2.15.

Test case below, does not assert with glibc-2.15, but asserts with current
trunk.

If I use fopen() instead of fdopen() ["./a.out -o"] or if I fflush() after
fwrite() ["./a.out -f"], then assert goes away.

/* --- cut --- */
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  FILE *fp;
  size_t written;
  off_t off;
  int do_flush = 0, do_fopen = 0;
  int opt;
  const char *const fname = "/tmp/output";

  while ((opt = getopt (argc, argv, "fo")) != -1)
    {
      switch (opt)
        {
        case 'f': do_flush = 1; break;
        case 'o': do_fopen = 1; break;
        }
    }

  fp = fopen (fname, "w");
  written = fwrite ("abcabc", 1, 6, fp);
  assert (written == 6);

  fclose (fp);

  if (do_fopen)
    fp = fopen (fname, "a");
  else
    {
      int fd = open (fname, O_WRONLY, 0);
      assert (fd != -1);
      fp = fdopen (fd, "a");
    }

  assert (fp != NULL);

  written = fwrite ("ghi", 1, 3, fp);
  assert (written == 3);

  if (do_flush)
    fflush (NULL);

  off = ftello (fp);
  assert (off == 9);

  return 0;
}
/* --- cut --- */

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


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

* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
  2014-02-06  3:38 ` [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() " ppluzhnikov at google dot com
@ 2014-02-06 22:28 ` ppluzhnikov at google dot com
  2014-02-07  4:06 ` siddhesh at redhat dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppluzhnikov at google dot com @ 2014-02-06 22:28 UTC (permalink / raw)
  To: glibc-bugs

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

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |siddhesh at redhat dot com

--- Comment #1 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
This broke with commit adb26faefe47b7d34c941cbfc193ca7a5fde8e3f:


 2012-09-28  Siddhesh Poyarekar  <siddhesh@redhat.com>

      [BZ #5298]
       * libio/fileops.c (_IO_new_file_seekoff): Don't flush buffer
       for ftell.  Compute offsets from write pointers instead.
       * libio/wfileops.c (_IO_wfile_seekoff): Likewise.

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


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

* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
  2014-02-06  3:38 ` [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() " ppluzhnikov at google dot com
  2014-02-06 22:28 ` ppluzhnikov at google dot com
@ 2014-02-07  4:06 ` siddhesh at redhat dot com
  2014-02-07  4:07 ` siddhesh at redhat dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: siddhesh at redhat dot com @ 2014-02-07  4:06 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |siddhesh at redhat dot com

--- Comment #2 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
Thanks, I'll look into it.

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


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

* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
                   ` (2 preceding siblings ...)
  2014-02-07  4:06 ` siddhesh at redhat dot com
@ 2014-02-07  4:07 ` siddhesh at redhat dot com
  2014-02-21  4:43 ` siddhesh at redhat dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: siddhesh at redhat dot com @ 2014-02-07  4:07 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

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


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

* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
                   ` (3 preceding siblings ...)
  2014-02-07  4:07 ` siddhesh at redhat dot com
@ 2014-02-21  4:43 ` siddhesh at redhat dot com
  2014-03-04  9:06 ` siddhesh at redhat dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ 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=16532

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugdal at aerifal dot cx

--- Comment #3 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
*** Bug 16605 has been marked as a duplicate of this bug. ***

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


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

* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
                   ` (4 preceding siblings ...)
  2014-02-21  4:43 ` siddhesh at redhat dot com
@ 2014-03-04  9:06 ` siddhesh at redhat dot com
  2014-06-13  8:41 ` fweimer at redhat dot com
  2014-09-10 19:50 ` tim.lammens at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: siddhesh at redhat dot com @ 2014-03-04  9:06 UTC (permalink / raw)
  To: glibc-bugs

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

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

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

--- Comment #4 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
Fixed in master:

commit 000232b9bcbf194f1e5fd0ff380000f341505405
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date:   Tue Mar 4 07:45:58 2014 +0530

    Separate ftell from fseek logic and avoid modifying FILE data (#16532)

    ftell semantics are distinct from fseek(SEEK_CUR) especially when it
    is called on a file handler that is not yet active.  Due to this
    caveat, much care needs to be taken while modifying the handler data
    and hence, this first iteration on separating out ftell focusses on
    maintaining handler data integrity at all times while it figures out
    the current stream offset.  The result is that it makes a syscall for
    every offset request.

    There is scope for optimizing this by caching offsets when we know
    that the handler is active.  A simple way to find out is when the
    buffers have data.  It is not so simple to find this out when the
    buffer is empty without adding some kind of flag.

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


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

* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
                   ` (5 preceding siblings ...)
  2014-03-04  9:06 ` siddhesh at redhat dot com
@ 2014-06-13  8:41 ` fweimer at redhat dot com
  2014-09-10 19:50 ` tim.lammens at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13  8:41 UTC (permalink / raw)
  To: glibc-bugs

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

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

* [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() sequence gives wrong answer
  2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
                   ` (6 preceding siblings ...)
  2014-06-13  8:41 ` fweimer at redhat dot com
@ 2014-09-10 19:50 ` tim.lammens at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: tim.lammens at gmail dot com @ 2014-09-10 19:50 UTC (permalink / raw)
  To: glibc-bugs

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

Tim <tim.lammens at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tim.lammens at gmail dot com

--- Comment #5 from Tim <tim.lammens at gmail dot com> ---
I am afraid the provided fix has caused a memory leak.
See https://sourceware.org/bugzilla/show_bug.cgi?id=17370.
The malloc in the patch has not been freed.

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


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

end of thread, other threads:[~2014-09-10 19:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-06  3:38 [Bug stdio/16532] New: fdopen(..., "a"); fwrite(); ftell() sequence gives wrong answer ppluzhnikov at google dot com
2014-02-06  3:38 ` [Bug stdio/16532] fdopen(..., "a"); fwrite(); ftello() " ppluzhnikov at google dot com
2014-02-06 22:28 ` ppluzhnikov at google dot com
2014-02-07  4:06 ` siddhesh at redhat dot com
2014-02-07  4:07 ` siddhesh at redhat dot com
2014-02-21  4:43 ` siddhesh at redhat dot com
2014-03-04  9:06 ` siddhesh at redhat dot com
2014-06-13  8:41 ` fweimer at redhat dot com
2014-09-10 19:50 ` tim.lammens at gmail 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).