]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
locale: Use correct buffer size for utf8_sequence_error [BZ #19444]
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 29 Dec 2022 12:57:59 +0000 (09:57 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 11 Jan 2023 20:50:12 +0000 (17:50 -0300)
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>
locale/programs/linereader.c

index 17099af744dbccb9a60dc89dc5e8b52b32f042b9..f8c49ac06f3bc53e898ee978b7a11e41b41f424c 100644 (file)
@@ -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);