Message ID | 20250507142110.3452012-4-adhemerval.zanella@linaro.org |
---|---|
State | New |
Headers | show |
Series | Add initial support for --enable-ubsan | expand |
* Adhemerval Zanella: > 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 [2147483649, 4294967295] 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 [2147483649, 4294967295] 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. Isn't this either a real source bug or a GCC bug? Why paper over it? Thanks, Florian
diff --git a/locale/programs/charmap.c b/locale/programs/charmap.c index 7768a7a7fc..58433c8c5b 100644 --- a/locale/programs/charmap.c +++ b/locale/programs/charmap.c @@ -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; diff --git a/locale/programs/charmap.h b/locale/programs/charmap.h index dcdbfe1828..b4aa8d6b6c 100644 --- a/locale/programs/charmap.h +++ b/locale/programs/charmap.h @@ -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; diff --git a/locale/programs/repertoire.c b/locale/programs/repertoire.c index 7ed8c915dd..99f560fc45 100644 --- a/locale/programs/repertoire.c +++ b/locale/programs/repertoire.c @@ -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;