diff options
| author | Joseph Myers <josmyers@redhat.com> | 2025-01-28 22:35:21 +0000 |
|---|---|---|
| committer | Joseph Myers <josmyers@redhat.com> | 2025-01-28 22:35:21 +0000 |
| commit | 0dcc0b2f63051863187dc678964eb17761b1a820 (patch) | |
| tree | b6a9d78ad868c01dad143e4f5160ec84443ca9c3 /libio | |
| parent | 94251ae99edaa911f4cb8056748dca0874ea268c (diff) | |
| download | glibc-0dcc0b2f63051863187dc678964eb17761b1a820.tar.xz glibc-0dcc0b2f63051863187dc678964eb17761b1a820.zip | |
Fix fseek handling for mmap files after ungetc or fflush (bug 32529)
As discussed in bug 32529, fseek fails on files opened for reading
using mmap after ungetc. The implementation of fseek for such files
has an offset computation that's also incorrect after fflush. A
combined fix addresses both problems (with tests for both included as
well) and it seems reasonable to consider them a single bug.
Tested for x86_64.
Diffstat (limited to 'libio')
| -rw-r--r-- | libio/fileops.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libio/fileops.c b/libio/fileops.c index e868d520b6..b00a5d24ab 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -1107,11 +1107,18 @@ _IO_file_seekoff_mmap (FILE *fp, off64_t offset, int dir, int mode) if (mode == 0) return fp->_offset - (fp->_IO_read_end - fp->_IO_read_ptr); + if (_IO_in_backup (fp)) + { + if (dir == _IO_seek_cur) + offset += fp->_IO_read_ptr - fp->_IO_read_end; + _IO_switch_to_main_get_area (fp); + } + switch (dir) { case _IO_seek_cur: /* Adjust for read-ahead (bytes is buffer). */ - offset += fp->_IO_read_ptr - fp->_IO_read_base; + offset += fp->_offset - (fp->_IO_read_end - fp->_IO_read_ptr); break; case _IO_seek_set: break; |
