diff options
author | Joseph Myers <josmyers@redhat.com> | 2025-01-28 23:20:08 +0000 |
---|---|---|
committer | Joseph Myers <josmyers@redhat.com> | 2025-01-28 23:20:08 +0000 |
commit | 3ff3b9997cfef891ba33a14f1dcba0310d96369c (patch) | |
tree | 087c3af4b133e92e7e7063c695ae9bf9120b31b6 /libio | |
parent | 0dcc0b2f63051863187dc678964eb17761b1a820 (diff) | |
download | glibc-3ff3b9997cfef891ba33a14f1dcba0310d96369c.zip glibc-3ff3b9997cfef891ba33a14f1dcba0310d96369c.tar.gz glibc-3ff3b9997cfef891ba33a14f1dcba0310d96369c.tar.bz2 |
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.
Diffstat (limited to 'libio')
-rw-r--r-- | libio/fileops.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libio/fileops.c b/libio/fileops.c index b00a5d2..1a192b7 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -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; } |