This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug stdio/18549] New: fmemopen getc allows segfault at EOF


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

            Bug ID: 18549
           Summary: fmemopen getc allows segfault at EOF
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: quae at daurnimator dot com
  Target Milestone: ---

If you "getc" through an fmemopen'd FILE*, fwrite seems to be able to write
past EOF; which will cause a segfault on fclose.


#define _GNU_SOURCE

#include <stdio.h> /* fmemopen */

int main() {
        FILE *f = fmemopen(NULL, 100, "w+b");
        if (!f) return (perror("fmemopen"), 1);
        /* read until EOF */
        int c;
        while ((c = getc(f)) != EOF) { }
        /* write something */
        printf("Write %d bytes.\n", fwrite("asd", 3, 1, f));
        /* fclose segfaults for me */
        fclose(f);
        return 0;
}

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]