From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH 2/4] libelf: elf32_getshdr might leak section header when out of memory
Date: Sun, 23 Jun 2024 01:50:11 +0200 [thread overview]
Message-ID: <20240622235013.2071424-2-mark@klomp.org> (raw)
In-Reply-To: <20240622235013.2071424-1-mark@klomp.org>
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
next prev parent reply other threads:[~2024-06-22 23:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-22 23:50 [PATCH 1/4] libdwfl: Make sure mapped is always set in unzip Mark Wielaard
2024-06-22 23:50 ` Mark Wielaard [this message]
2024-06-22 23:50 ` [PATCH 3/4] debuginfod-client: Don't leak id/version with duplicate os-release entries Mark Wielaard
2024-06-22 23:50 ` [PATCH 4/4] ar, ranlib: Don't double close file descriptors Mark Wielaard
2024-06-25 20:18 ` [PATCH 1/4] libdwfl: Make sure mapped is always set in unzip Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240622235013.2071424-2-mark@klomp.org \
--to=mark@klomp.org \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).