This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/18549] New: fmemopen getc allows segfault at EOF
- From: "quae at daurnimator dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 17 Jun 2015 11:25:06 +0000
- Subject: [Bug stdio/18549] New: fmemopen getc allows segfault at EOF
- Auto-submitted: auto-generated
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.