|
Message-ID: <20171119011257.GG1627@brightrain.aerifal.cx>
Date: Sat, 18 Nov 2017 20:12:57 -0500
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] fix fgetwc when decoding a character that crosses
buffer boundary
On Sat, Nov 18, 2017 at 05:51:48PM +0100, Szabolcs Nagy wrote:
> Update the buffer position according to the bytes consumed into st when
> decoding an incomplete character at the end of the buffer.
> ---
> src/stdio/fgetwc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/src/stdio/fgetwc.c b/src/stdio/fgetwc.c
> index e455cfec..a00c1a86 100644
> --- a/src/stdio/fgetwc.c
> +++ b/src/stdio/fgetwc.c
> @@ -15,20 +15,21 @@ static wint_t __fgetwc_unlocked_internal(FILE *f)
> if (f->rpos < f->rend) {
> l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st);
> if (l+2 >= 2) {
> f->rpos += l + !l; /* l==0 means 1 byte, null */
> return wc;
> }
> if (l == -1) {
> f->rpos++;
> return WEOF;
> }
> + f->rpos = f->rend;
> } else l = -2;
Thanks, applying! Here is a test case that demonstrates the bug
reproducibly; feel free to adapt (it should probably use the framework
functions for getting a utf-8 locale and error reporting) & include it
in libc-test.
Rich
View attachment "fgetwc2.c" of type "text/plain" (325 bytes)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.