From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=nabijaczleweli.xyz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nabijaczleweli.xyz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1690133613; bh=lBo0/xKp6XcIh644+TtFC6AcTav+JZCnOw1OEG5SACE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=U99J+/w+ITqIFIJG/wdjfVWpSKUPZpetX15S/PircBBkfdfoz4OJDoCqMYz0s7vDF 23jqhTRaEBXS368NQ8CUp6BcWB1sEtX2O9/UcgoTN2B3huOZKCXNHIjlX3m11vRqoA j0+ZG3fsAxkGjvY7lyyyrbko6Wi/tjYKjgbKN1IDAV29+aaiZ2KRszH2UGNmpazbPk jE7XjHjBhyf8lZJmOOHRgADwQ74g8hrdxeoagbpRqCbcKL1CtAFKpYjshlvSOWLYp3 GEwMQdw6rqzQ9QdT04SnmGC9evpVHGdx6wjSy4eoRaBtDaZTfreC+9WBD/b6IGBh63 dEP/dPCAKHUqg== 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 From: =?utf-8?B?0L3QsNCx?= 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-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="he6paxfpp3i47k5q" 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 List-Id: --he6paxfpp3i47k5q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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=C5=84ska --- 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 cha= racters")); =20 for (cnt =3D from_nr; cnt <=3D to_nr; cnt +=3D step) { + /* Increment the value in the byte sequence. */ + if (cnt !=3D from_nr && ++bytes[nbytes - 1] =3D=3D '\0') + { + int b =3D nbytes - 2; + do + if (b < 0) + { + lr_error (lr, + _("resulting bytes for range not representable.")); + return; + } + while (++bytes[b--] =3D=3D 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 cha= racters")); 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] =3D=3D '\0') - { - int b =3D nbytes - 2; - - do - if (b < 0) - { - lr_error (lr, - _("resulting bytes for range not representable.")); - return; - } - while (++bytes[b--] =3D=3D 0); - } } } =20 --=20 2.39.2 --he6paxfpp3i47k5q Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEfWlHToQCjFzAxEFjvP0LAY0mWPEFAmS9ZGsACgkQvP0LAY0m WPGS1A/+La3bhbY6qc3DWLgEzSt7SuHZEG6XfRDJ8SQcIj8QGcjk5bugb6TozhC7 XMxusIyLBWfWfBmxRXnvSu9x23sw2DCd1uoka1VlZ/7WbhGnWoFe3OGM7nlBd/H9 oddZiXMTt7258QQW9HBgmOSK8s40ZTzmJvGqCgILObNUorCDi4arSodGVAEUnxhy 9W29xpYPbf3ipwUFmrqhc5jwx/i/4TLDU8BcKyTOYn5o8AL9bWfKA4fh4M5th9y+ gMVVaoacdIxn9TKNm71+MhqzRa8WGgKcgDbRj3LgvlLRLUow5BHwbP2oSgoDLwTK R7lb8jLwnPqDODieI0WWEIHDAmPZ14/yqLkgb4Nin2K5CCP9dS3/m0vNDA3ecPk+ Zqt20LPWWXsDPzEtWlNuZ0F2W4QTSefZHUZK1c2xJJgtaIYI81dfJcnYygk6t5gA Ux6I2u3N9p8wKJPt0/ty+z6krNYJiQWBsFGnXVaraAAwSUpomK7xqK/lSEV2JDOZ jGCqJYs5SiPSUQhuZYrQl/mgEyR6T/V9QiRvyZ4QrlFHtvoPvwMEvNUmhg1iXDcd OET/yq2NGZkixy9zQVB/N72KlP1PL+fR9OzK/HNWtvmZDW2iTXua3jP0UGc4pW+Q z/l6MAqqgkjgZJrGBcDmZ0cfMvYMPb5oeDCHD1mZW8Uo6hBb0e8= =49O4 -----END PGP SIGNATURE----- --he6paxfpp3i47k5q--