This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/20012] libio: fmemopen append mode failure
- From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Fri, 29 Apr 2016 22:31:25 +0000
- Subject: [Bug stdio/20012] libio: fmemopen append mode failure
- Auto-submitted: auto-generated
- References: <bug-20012-131 at http dot sourceware dot org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=20012
--- Comment #1 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, master has been updated
via b65b205fbcabbb02463e31df17f5cabf7556f892 (commit)
from 0cb313f7cb0e418b3d56f3a2ac69790522ab825d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b65b205fbcabbb02463e31df17f5cabf7556f892
commit b65b205fbcabbb02463e31df17f5cabf7556f892
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Wed Apr 27 11:51:01 2016 -0300
libio: Fix fmemopen append mode failure (BZ# 20012)
The fmemopen implementation does not account the file position correctly in
append mode. The following example shows the failure:
===
int main ()
{
char buf[10] = "test";
FILE *fp = fmemopen (buf, 10, "a+");
fseek (fp, 0, SEEK_SET);
int gr;
if ((gr = getc (fp)) != 't' ||
(gr = getc (fp)) != 'e' ||
(gr = getc (fp)) != 's' ||
(gr = getc (fp)) != 't' ||
(gr = getc (fp)) != EOF)
{
printf ("%s: getc failed returned %i\n", __FUNCTION__, gr);
return 1;
}
return 0;
}
===
This is due both how read and write operation update the buffer position,
taking in consideration buffer lenght instead of maximum position defined
by the open mode. This patch fixes it and also fixes fseek not returning
EINVAL for invalid whence modes.
Tested on x86_64 and i686.
[BZ #20012]
* libio/fmemopen.c (fmemopen_read): Use buffer maximum position, not
length to calculate the buffer to read.
(fmemopen_write): Set the buffer position based on bytes written.
(fmemopen_seek): Return EINVAL for invalid whence modes.
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 6 ++
libio/fmemopen.c | 28 +++++-----
stdio-common/tst-fmemopen3.c | 118 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 138 insertions(+), 14 deletions(-)
--
You are receiving this mail because:
You are on the CC list for the bug.