]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
locale: Fix UB on add_locale_uint32_array
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 18 Apr 2025 12:29:21 +0000 (09:29 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:20:40 +0000 (14:20 -0300)
The ubsan triggers:

UBSAN: Undefined behaviour in programs/locfile.c:644:3 null pointer passed as argument 2, nonnull attribute declared at unknown:0:0

The obstack_grow is only required if there is extra elements to be
inserted (n_elems > 0).

locale/programs/locfile.c

index b54fcbbcebaa0803fc74ad6b442c60bc6cf5d6dc..7907c949eab9cdbaa40ceac23b3b530493f7e116 100644 (file)
@@ -641,6 +641,8 @@ add_locale_uint32_array (struct locale_file *file,
 {
   align_locale_data (file, LOCFILE_ALIGN);
   record_offset (file);
+  if (n_elems == 0)
+    return;
   obstack_grow (&file->data, data, n_elems * sizeof (uint32_t));
   maybe_swap_uint32_obstack (&file->data, n_elems);
 }