From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7069 invoked by alias); 17 Jun 2014 17:35:44 -0000 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org Received: (qmail 7055 invoked by uid 48); 17 Jun 2014 17:35:40 -0000 From: "ppluzhnikov at google dot com" To: glibc-bugs@sourceware.org Subject: [Bug stdio/17063] New: fclose() may fail to flush data Date: Tue, 17 Jun 2014 17:35:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: stdio X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ppluzhnikov at google dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-06/txt/msg01176.txt.bz2 https://sourceware.org/bugzilla/show_bug.cgi?id=17063 Bug ID: 17063 Summary: fclose() may fail to flush data 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 followup to PR16532. A program that does fopen(..., "w+"); fwrite(...); fread(...); fclose(); may leave empty file on disk (fail to flush when it should have), when the fread requests more than a page's worth of data. At least glibc-2.19 through current trunk (754c5a08aacb44895d1ab97c553ce424eb43f761) are affected. ./t testing 3 testing 3 OK testing 6 testing 6 OK testing 9 testing 9 OK testing 4095 testing 4095 OK testing 4096 t: t.c:28: do_test: Assertion `pos == 6' failed. Aborted /// --- cut --- #include #include void do_test (int n) { FILE *fp; const char *const fname = "/tmp/output"; int nwritten, nread, pos; char line[8192]; printf ("testing %5d\n", n); fp = fopen (fname, "w+"); nwritten = fwrite ("abcabc", 1, 6, fp); assert (nwritten == 6); pos = ftello (fp); assert (pos == 6); nread = fread (line, 1, n, fp); assert (nread == 0); fclose (fp); fp = fopen (fname, "r"); fseeko (fp, 0, SEEK_END); pos = ftello (fp); assert (pos == 6); printf ("testing %5d OK\n", n); } int main(int argc, char *argv[]) { int j, nreads[] = { 3, 6, 9, 4095, 4096, 4097, 8191, 8192 }; for (j = 0; j < sizeof (nreads) / sizeof (nreads[0]); ++j) do_test (nreads[j]); return 0; } -- You are receiving this mail because: You are on the CC list for the bug.