libio: Check remaining buffer size in _IO_wdo_write (bug 31183)
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Testing passed
|
redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Testing passed
|
Commit Message
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
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.
@@ -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. */