]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
libio: Check remaining buffer size in _IO_wdo_write (bug 31183)
authorFlorian Weimer <fweimer@redhat.com>
Tue, 2 Jan 2024 13:36:17 +0000 (14:36 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 2 Jan 2024 13:36:17 +0000 (14:36 +0100)
The multibyte character needs to fit into the remaining buffer space,
not the already-written buffer space.  Without the fix, we were never
moving the write pointer from the start of the buffer, always using
the single-character fallback buffer.

Fixes commit 04b76b5aa8b2d1d19066e42dd1 ("Don't error out writing
a multibyte character to an unbuffered stream (bug 17522)").

libio/wfileops.c

index 17384296e63b53c193b2fa019afbd11c5aedb836..6de59683587b40b4a832742988b99874b6d8c2fc 100644 (file)
@@ -55,7 +55,7 @@ _IO_wdo_write (FILE *fp, const wchar_t *data, size_t to_do)
          char mb_buf[MB_LEN_MAX];
          char *write_base, *write_ptr, *buf_end;
 
-         if (fp->_IO_write_ptr - fp->_IO_write_base < sizeof (mb_buf))
+         if (fp->_IO_buf_end - fp->_IO_write_ptr < sizeof (mb_buf))
            {
              /* Make sure we have room for at least one multibyte
                 character.  */