From patchwork Sun Jul 23 17:33:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ahelenia_Ziemia=C5=84ska?= X-Patchwork-Id: 73102 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FE173857734 for ; Sun, 23 Jul 2023 17:33:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FE173857734 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690133635; bh=ozltXSyy8LWCotS+IF5+/Wu2bu6w5JpJEuG9lhr+bA4=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Yqa8+HK9/OY8t42+Cs41lMPzWkLq4c/bX2vRfEN6Y2ke8hSQPvgJa4So3Gbf+uufB X/onUAF0Lc9utFba04WSNFuWB2G0pCKwrvuoZvy0tIO0riNx4o0+dOmSY3/wCER6n5 k/kVxnHfDp7E9uC8BUQGMCpecuy+1bNmDZRuBseI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by sourceware.org (Postfix) with ESMTP id B6F2E3858C2D for ; Sun, 23 Jul 2023 17:33:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6F2E3858C2D Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 0E92337F4; Sun, 23 Jul 2023 19:33:33 +0200 (CEST) Date: Sun, 23 Jul 2023 19:33:31 +0200 To: Florian Weimer Cc: libc-alpha@sourceware.org, Victor Stinner , Bruno Haible Subject: [PATCH v18 2/3] locale: charmap: fix off-by-one with ranges Message-ID: <946054e4f257b2273103c021f49daf7187919a0a.1690133538.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20230517 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, RDNS_DYNAMIC, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?b?0L3QsNCxIHZpYSBMaWJjLWFscGhh?= From: =?utf-8?q?Ahelenia_Ziemia=C5=84ska?= Reply-To: =?utf-8?b?0L3QsNCx?= Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The "current character" bytes array was incremented at the end of the loop instead of at the beginning, which meant that for ASCII + .. /x80 it would complain about overrunning 0xFF->0x100 when in reality the loop would've ended just after. Instead, bump the current character at the start of the loop (but not the first time, of course), precisely as many times as there are characters in the range. Signed-off-by: Ahelenia ZiemiaƄska --- New patch, trivial and obvious off-by-1. locale/programs/charmap.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/locale/programs/charmap.c b/locale/programs/charmap.c index e4847aa3a0..822239ef11 100644 --- a/locale/programs/charmap.c +++ b/locale/programs/charmap.c @@ -1037,6 +1037,20 @@ hexadecimal range format should use only capital characters")); for (cnt = from_nr; cnt <= to_nr; cnt += step) { + /* Increment the value in the byte sequence. */ + if (cnt != from_nr && ++bytes[nbytes - 1] == '\0') + { + int b = nbytes - 2; + do + if (b < 0) + { + lr_error (lr, + _("resulting bytes for range not representable.")); + return; + } + while (++bytes[b--] == 0); + } + char *name_end; obstack_printf (ob, decimal_ellipsis ? "%.*s%0*d" : "%.*s%0*X", prefix_len, from, len1 - prefix_len, cnt); @@ -1079,21 +1093,6 @@ hexadecimal range format should use only capital characters")); insert_entry (bt, newp->bytes, nbytes, newp); /* Please note we don't examine the return value since it is no error if we have two definitions for a symbol. */ - - /* Increment the value in the byte sequence. */ - if (++bytes[nbytes - 1] == '\0') - { - int b = nbytes - 2; - - do - if (b < 0) - { - lr_error (lr, - _("resulting bytes for range not representable.")); - return; - } - while (++bytes[b--] == 0); - } } }