[PATCH 2/4] libelf: elf32_getshdr might leak section header when out of memory
Mark Wielaard
mark@klomp.org
Sat Jun 22 23:50:11 GMT 2024
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libelf/elf32_getshdr.c b/libelf/elf32_getshdr.c
index fc696302b8b6..19b690a8e87b 100644
--- a/libelf/elf32_getshdr.c
+++ b/libelf/elf32_getshdr.c
@@ -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),
--
2.45.2
More information about the Elfutils-devel
mailing list