From: Adhemerval Zanella Date: Fri, 18 Apr 2025 12:29:21 +0000 (-0300) Subject: locale: Fix UB on add_locale_uint32_array X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5c20a5be6835a73f43ec09ee5d3e50379874b14;p=thirdparty%2Fglibc.git locale: Fix UB on add_locale_uint32_array 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). --- diff --git a/locale/programs/locfile.c b/locale/programs/locfile.c index b54fcbbceb..7907c949ea 100644 --- a/locale/programs/locfile.c +++ b/locale/programs/locfile.c @@ -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); }