From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12111 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] fix fgetwc when decoding a character that crosses buffer boundary Date: Sat, 18 Nov 2017 17:51:48 +0100 Message-ID: <20171118165148.GF15263@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1511023934 28989 195.159.176.226 (18 Nov 2017 16:52:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 18 Nov 2017 16:52:14 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-12127-gllmg-musl=m.gmane.org@lists.openwall.com Sat Nov 18 17:52:10 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1eG6LZ-0006YD-HF for gllmg-musl@m.gmane.org; Sat, 18 Nov 2017 17:52:01 +0100 Original-Received: (qmail 3713 invoked by uid 550); 18 Nov 2017 16:52:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3678 invoked from network); 18 Nov 2017 16:52:00 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:12111 Archived-At: 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