diff mbox series

libio: Check remaining buffer size in _IO_wdo_write (bug 31183)

Message ID 87bkakx3b0.fsf@oldenburg.str.redhat.com
State New
Headers show
Series libio: Check remaining buffer size in _IO_wdo_write (bug 31183) | expand

Commit Message

Florian Weimer Dec. 20, 2023, 4:10 p.m. UTC
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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: 61bac1a9d2ab80ebcbc51484722e6ea43414bec7

Comments

Andreas Schwab Jan. 2, 2024, 10:10 a.m. UTC | #1
On Dez 20 2023, Florian Weimer wrote:

> 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)").

Ok.

I don't know how I managed to get that so wrong.
diff mbox series

Patch

diff --git a/libio/wfileops.c b/libio/wfileops.c
index f16f6db1c3..9ab8f2e7f3 100644
--- a/libio/wfileops.c
+++ b/libio/wfileops.c
@@ -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.  */