glibc/manual/examples
Adhemerval Zanella 645f97ced4 libio: Multiple fixes for open_{w}memstram (BZ#18241 and BZ#20181)
This patches fixes multiples issues on open_{w}memstream reported on both
BZ#18241 and BZ#20181:

  - failed fseek does not set errno.
  - negative offset in fseek fails even when resulting position is
    a valid one.
  - a flush after write if the current write position is not at the
    end of the stream currupt data.

The main fix is on seek operation for memstream (_IO_{w}str_seekoff), where
both _IO_read_ptr and _IO_read_end pointer are updated if a write operation
has occured (similar to default file operations).  Also, to calculate the
offset on both read and write pointers, a temporary value is instead of
updating the argument supplied value.  Negative offset are valid if resulting
internal pointer is within the range of _IO_{read,write}_base and
_IO_{read,write}_end.

Also POSIX states that a null or wide null shall be appended to the current
buffer iff a write moves the position to a value larger than the current
lenght.  Current implementation appends a null or wide null regardless
of this condition.  This patch fixes it by removing the 'else' condition
on _IO_{w}mem_sync.

Checked on x86_64.

	[BZ #18241]
	[BZ #20181]
	* libio/Makefile (test): Add tst-memstream3 and tst-wmemstream3.
	* libio/memstream.c (_IO_mem_sync): Only append a null byte if
	write position is at the end the buffer.
	* libio/wmemstream.c (_IO_wmem_sync): Likewise.
	* libio/strops.c (_IO_str_switch_to_get_mode): New function.
	(_IO_str_seekoff): Set correct offset from negative displacement and
	set EINVAL for invalid ones.
	* libio/wstrops.c (enlarge_userbuf): Use correct function to calculate
	buffer length.
	(_IO_wstr_switch_to_get_mode): New function.
	(_IO_wstr_seekoff): Set correct offset from negative displacement and
	set EINVAL for invalid ones.
	* libio/tst-memstream3.c: New file.
	* libio/tst-wmemstream3.c: Likewise.
	* manual/examples/memstrm.c: Remove warning when priting size_t.
2016-09-30 09:14:15 -07:00
..
add.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
argp-ex1.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
argp-ex2.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
argp-ex3.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
argp-ex4.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
atexit.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
db.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
dir2.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
dir.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
execinfo.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
filecli.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
filesrv.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
fmtmsgexpl.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
genpass.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
inetcli.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
inetsrv.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
isockad.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
longopt.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
memopen.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
memstrm.c libio: Multiple fixes for open_{w}memstram (BZ#18241 and BZ#20181) 2016-09-30 09:14:15 -07:00
mkdirent.c glob: Simplify the interface for the GLOB_ALTDIRFUNC callback gl_readdir 2016-04-29 09:35:30 +02:00
mkfsock.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
mkisock.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
mygetpass.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
ofdlocks.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
pipe.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
popen.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
README BZ #13792: License manual example source files under GPL. 2012-03-02 16:52:01 -08:00
rprintf.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
search.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
select.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
setjmp.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
sigh1.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
sigusr.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
stpcpy.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
strdupa.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
strftim.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
subopt.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
swapcontext.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
termios.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
testopt.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
testpass.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
timeval_subtract.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00

These are source files for example code that appears in The GNU C
Library Reference Manual.

While the manual itself is licensed under the terms of the GNU Free
Documentation License, you can use these source files on their own
under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License, or (at your
option) any later version.