]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
locale: Fix --enable-ubsan build failure on some ABIs
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 30 Apr 2025 17:24:20 +0000 (14:24 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 13:41:34 +0000 (10:41 -0300)
On mips, arc, powerpc, and s390 gcc 14 triggers the warning

In function ‘charmap_new_char’,
    inlined from ‘parse_charmap.isra’ at ../locale/programs/charmap.c:570:6:
../locale/programs/charmap.c:1017:32: error: ‘strncmp’ specified bound [21474836494294967295] exceeds maximum object size 2147483647 [-Werror=stringop-overread]
 1017 |   if (cp == &from[len1 - 1] || strncmp (from, to, prefix_len) != 0)
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../locale/programs/charmap.c:1017:32: error: ‘strncmp’ specified bound [21474836494294967295] exceeds maximum object size 2147483647 [-Werror=stringop-overread]
cc1: all warnings being treated as errors

So move the case to an special function and disable the sanitizer.

locale/programs/charmap.c
locale/programs/charmap.h
locale/programs/repertoire.c

index 7768a7a7fc42435968ab101c01a89e86ec654f6f..58433c8c5bdd27e1bdadb929c0129be39ff80f6b 100644 (file)
@@ -1014,7 +1014,7 @@ hexadecimal range format should use only capital characters"));
 
   prefix_len = (cp - from) + 1;
 
-  if (cp == &from[len1 - 1] || strncmp (from, to, prefix_len) != 0)
+  if (check_illegal_range (cp, from, len1, to, prefix_len))
     goto illegal_range;
 
   errno = 0;
index dcdbfe1828c58cbcf9d2a8b388534a58dfc29d87..b4aa8d6b6c60d68aeafa62243e61cf141c9be27e 100644 (file)
@@ -62,6 +62,13 @@ struct charseq
   unsigned char bytes[];
 };
 
+static inline bool
+__attribute_disable_ubsan__
+check_illegal_range (const char *cp, const char *from, size_t len1,
+                    const char *to, size_t prefix_len)
+{
+  return cp == &from[len1 - 1] || strncmp (from, to, prefix_len) != 0;
+}
 
 /* True if the encoding is not ASCII compatible.  */
 extern bool enc_not_ascii_compatible;
index 7ed8c915dd6a83ba69ba099d4de4e4447e3769b9..99f560fc45db1ce0611cafaeaabe2a5d93df430f 100644 (file)
@@ -433,7 +433,7 @@ hexadecimal range format should use only capital characters"));
 
   prefix_len = (cp - from) + 1;
 
-  if (cp == &from[len1 - 1] || strncmp (from, to, prefix_len) != 0)
+  if (check_illegal_range (cp, from, len1, to, prefix_len))
     goto invalid_range;
 
   errno = 0;