]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elfcompress: Don't over allocate sections bitmap
authorMark Wielaard <mark@klomp.org>
Mon, 18 May 2026 17:33:26 +0000 (19:33 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 21 May 2026 16:46:08 +0000 (18:46 +0200)
In process_file we allocate a bitmap sections to track which sections
we want to (de)compress. This allocates shnum / 8 + 1 unsigned
ints. But an unsigned int can contain more bits than just 8. In all
other places we use WORD_BITS defined as 8U * sizeof (unsigned int).
Also use WORD_BITS to calculate how many unsigned ints we need for the
sections bitmap.

* src/elfcompress.c (process_file): Use shnum / WORD_BITS + 1
to allocate sections.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/elfcompress.c

index f771b92afabf9974e3e2cf26d4ea3bd2bd7a3789..630eb54da1c09adfd9b22fa6764613bda6446f12 100644 (file)
@@ -424,7 +424,7 @@ process_file (const char *fname)
       goto cleanup;
     }
 
-  sections = xcalloc (shnum / 8 + 1, sizeof (unsigned int));
+  sections = xcalloc (shnum / WORD_BITS + 1, sizeof (unsigned int));
 
   size_t phnum;
   if (elf_getphdrnum (elf, &phnum) != 0)