From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2178) id B9F60385C311; Tue, 5 Jul 2022 07:29:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9F60385C311 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Florian Weimer To: glibc-cvs@sourceware.org Subject: [glibc] locale: Fix signed char bug in lr_getc X-Act-Checkin: glibc X-Git-Author: Florian Weimer X-Git-Refname: refs/heads/master X-Git-Oldrev: 5dcbff5879a7d25e0dd511f4a71c039aa015e6a4 X-Git-Newrev: 19d494445981a09503e4a0175732745c39dd7c21 Message-Id: <20220705072936.B9F60385C311@sourceware.org> Date: Tue, 5 Jul 2022 07:29:36 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 07:29:36 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=19d494445981a09503e4a0175732745c39dd7c21 commit 19d494445981a09503e4a0175732745c39dd7c21 Author: Florian Weimer Date: Tue Jul 5 09:05:22 2022 +0200 locale: Fix signed char bug in lr_getc The array lr->buf contains characters, which can be signed. A 0xff byte in the input could be incorrectly reported as EOF. More importantly, get_string in linereader.c converts a signed input byte to a Unicode code point using ADDWC ((uint32_t) ch), under the assumption that this decodes the ISO-8859-1 input encoding. If char is signed, this does not give the correct result. This means that ISO-8859-1 input files for localedef are not actually supported, contrary to the comment in get_string. This is a happy accident because we can therefore change the file encoding to UTF-8 without impacting backwards compatibility. While at it, remove the \32 check for MS-DOS end-of-file character (^Z). Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell Diff: --- locale/programs/linereader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/programs/linereader.h b/locale/programs/linereader.h index 0fb10ec833..653a71d2d1 100644 --- a/locale/programs/linereader.h +++ b/locale/programs/linereader.h @@ -134,7 +134,7 @@ lr_getc (struct linereader *lr) return EOF; } - return lr->buf[lr->idx] == '\32' ? EOF : lr->buf[lr->idx++]; + return lr->buf[lr->idx++] & 0xff; }