Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Sat, 18 Nov 2017 17:51:48 +0100
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: [PATCH] fix fgetwc when decoding a character that crosses buffer
 boundary

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;
 
 	/* Convert character byte-by-byte */
 	while (l == -2) {
 		b = c = getc_unlocked(f);
 		if (c < 0) {
 			if (!mbsinit(&st)) errno = EILSEQ;
 			return WEOF;
 		}
 		l = mbrtowc(&wc, (void *)&b, 1, &st);
-- 
2.15.0

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.