1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-07 06:43:00 +03:00

Fix fflush handling for mmap files after ungetc (bug 32535)

As discussed in bug 32535, fflush fails on files opened for reading
using mmap after ungetc.  Fix the logic to handle this case and still
compute the file offset correctly.

Tested for x86_64.
This commit is contained in:
Joseph Myers
2025-01-28 23:20:08 +00:00
parent 0dcc0b2f63
commit 3ff3b9997c
3 changed files with 59 additions and 4 deletions

View File

@@ -859,17 +859,21 @@ libc_hidden_ver (_IO_new_file_sync, _IO_file_sync)
int
_IO_file_sync_mmap (FILE *fp)
{
off64_t o = fp->_offset - (fp->_IO_read_end - fp->_IO_read_ptr);
if (fp->_IO_read_ptr != fp->_IO_read_end)
{
if (__lseek64 (fp->_fileno, fp->_IO_read_ptr - fp->_IO_buf_base,
SEEK_SET)
!= fp->_IO_read_ptr - fp->_IO_buf_base)
if (_IO_in_backup (fp))
{
_IO_switch_to_main_get_area (fp);
o -= fp->_IO_read_end - fp->_IO_read_base;
}
if (__lseek64 (fp->_fileno, o, SEEK_SET) != o)
{
fp->_flags |= _IO_ERR_SEEN;
return EOF;
}
}
fp->_offset = fp->_IO_read_ptr - fp->_IO_buf_base;
fp->_offset = o;
fp->_IO_read_end = fp->_IO_read_ptr = fp->_IO_read_base;
return 0;
}