public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] locale: Use correct buffer size for utf8_sequence_error [BZ #19444]
Date: Wed, 11 Jan 2023 21:13:10 +0000 (GMT)	[thread overview]
Message-ID: <20230111211310.75E933857835@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0b3503e2e19602db9cda47915d19a26c00f59bb1

commit 0b3503e2e19602db9cda47915d19a26c00f59bb1
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Dec 29 09:57:59 2022 -0300

    locale: Use correct buffer size for utf8_sequence_error [BZ #19444]
    
    The buffer used by snprintf might not be large enough for all possible
    inputs, as indicated by gcc with -O1:
    
    ../locale/programs/linereader.c: In function ‘utf8_sequence_error’:
    ../locale/programs/linereader.c:713:58: error: ‘%02x’ directive output
    may be truncated writing between 2 and 8 bytes into a region of size
    between 1 and 13 [-Werror=format-truncation=]
      713 |     snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x",
          |                                                          ^~~~
    ../locale/programs/linereader.c:713:34: note: directive argument in the
    range [0, 2147483647]
      713 |     snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x",
          |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../locale/programs/linereader.c:713:5: note: ‘snprintf’ output between
    20 and 38 bytes into a destination of size 30
      713 |     snprintf (buf, sizeof (buf), "0x%02x 0x%02x 0x%02x 0x%02x",
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      714 |               ch1, ch2, ch3, ch4);
          |               ~~~~~~~~~~~~~~~~~~~
    
    Checked on x86_64-linux-gnu.
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>

Diff:
---
 locale/programs/linereader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/locale/programs/linereader.c b/locale/programs/linereader.c
index 17099af744..f8c49ac06f 100644
--- a/locale/programs/linereader.c
+++ b/locale/programs/linereader.c
@@ -701,7 +701,7 @@ static bool
 utf8_sequence_error (struct linereader *lr, uint8_t ch1, int ch2, int ch3,
 		     int ch4)
 {
-  char buf[30];
+  char buf[38];
 
   if (ch2 < 0)
     snprintf (buf, sizeof (buf), "0x%02x", ch1);

                 reply	other threads:[~2023-01-11 21:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230111211310.75E933857835@sourceware.org \
    --to=azanella@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /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).