public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org, Victor Stinner <vstinner@redhat.com>,
	 Bruno Haible <bruno@clisp.org>
Subject: [PATCH v18 2/3] locale: charmap: fix off-by-one with ranges
Date: Sun, 23 Jul 2023 19:33:31 +0200	[thread overview]
Message-ID: <946054e4f257b2273103c021f49daf7187919a0a.1690133538.git.nabijaczleweli@nabijaczleweli.xyz> (raw)
In-Reply-To: <e4748b3c5f06edfa928a649c99b6ea8dddb799f9.1690133538.git.nabijaczleweli@nabijaczleweli.xyz>

[-- Attachment #1: Type: text/plain, Size: 2069 bytes --]

The "current character" bytes array was incremented at the end of the
loop instead of at the beginning, which meant that for ASCII +
  <UDC80>..<UDCFF>  /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 <nabijaczleweli@nabijaczleweli.xyz>
---
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);
-	}
     }
 }
 
-- 
2.39.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-07-23 17:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-23 17:32 [PATCH v18 1/3] iconv: __gconv_btwoc_ascii -> __gconv_btowc_ascii наб
2023-07-23 17:33 ` наб [this message]
2023-07-23 19:38   ` [PATCH v18 2/3] locale: charmap: fix off-by-one with ranges Bruno Haible
2023-07-23 17:54 ` [PATCH v18 3/3] POSIX locale covers every byte [BZ# 29511] наб
2023-07-23 20:15   ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=946054e4f257b2273103c021f49daf7187919a0a.1690133538.git.nabijaczleweli@nabijaczleweli.xyz \
    --to=nabijaczleweli@nabijaczleweli.xyz \
    --cc=bruno@clisp.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=vstinner@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).