]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
localte: Fix UB on collate_finish
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 17 Apr 2025 21:08:01 +0000 (18:08 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:20:20 +0000 (14:20 -0300)
The ubsan triggers:

UBSAN: Undefined behaviour in programs/ld-collate.c:1557:7 variable length array bound evaluates to non-positive value 0

nrules is guaranteed to be at most sizeof (((struct element_t *)
0)->used_in_level) * 8, so use it instead.

locale/programs/ld-collate.c

index 4fa08bd273d5736366bac43d75f3874871a1fd3f..6ac132f21e0abeff41513532ba3163c7e063f64a 100644 (file)
@@ -1554,7 +1554,7 @@ collate_finish (struct localedef_t *locale, const struct charmap_t *charmap)
      The multibyte case is easy.  We simply sort into an array with
      256 elements.  */
   struct locale_collate_t *collate = locale->categories[LC_COLLATE].collate;
-  int mbact[nrules];
+  int mbact[sizeof (((struct element_t *)0)->used_in_level) * 8];
   int wcact;
   int mbseqact;
   int wcseqact;