]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: elf32_getshdr might leak section header when out of memory
authorMark Wielaard <mark@klomp.org>
Sat, 22 Jun 2024 23:09:29 +0000 (01:09 +0200)
committerMark Wielaard <mark@klomp.org>
Sat, 22 Jun 2024 23:09:39 +0000 (01:09 +0200)
Found by GCC -fanalyzer.

When allocating the notcvt buffer fails we leak the shdr. goto
free_and_out on malloc failure.

     * libelf/elf32_getshdr.c (load_shdr_wrlock): goto
             free_and_out on second malloc failure.

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

index fc696302b8b69ff39c13e114cd6a06a675d1c9f3..19b690a8e87bcdc2c9f7d596506859cde3cb9488 100644 (file)
@@ -126,7 +126,7 @@ load_shdr_wrlock (Elf_Scn *scn)
              if (unlikely (notcvt == NULL))
                {
                  __libelf_seterrno (ELF_E_NOMEM);
-                 goto out;
+                 goto free_and_out;
                }
              memcpy (notcvt, ((char *) elf->map_address
                               + elf->start_offset + ehdr->e_shoff),