|
Message-ID: <20171119011433.GH1627@brightrain.aerifal.cx> Date: Sat, 18 Nov 2017 20:14:33 -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 08:12:57PM -0500, Rich Felker wrote: > 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 > #include <stdio.h> > #include <poll.h> ^^^^^^^^ Ooops, this is spurious/leftover from when I thought I was going to need to do something fancier to reliably trigger it. > #include <locale.h> > #include <wchar.h> > #include <unistd.h> > > int main() > { > setlocale(LC_CTYPE, ""); > int p[2]; > pipe(p); > write(p[1], "x\340\240", 3); > dup2(p[0], 0); > wchar_t wc; > wc = fgetwc(stdin); > write(p[1], "\200", 1); > close(p[1]); > wc = fgetwc(stdin); > printf("got %x\n", wc); > }
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.