From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] libdwfl: Make sure there is at least one dynamic entry
Date: Fri, 17 Dec 2021 22:56:57 +0100 [thread overview]
Message-ID: <20211217215657.776086-1-mark@klomp.org> (raw)
The buffer read in needs to contain room for at least one Elf32_Dyn or
Elf64_Dyn entry.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libdwfl/ChangeLog | 5 +++++
libdwfl/link_map.c | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index f849b816..d4eee639 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2021-12-16 Mark Wielaard <mark@klomp.org>
+
+ * link_map.c (dwfl_link_map_report): Make sure dyn_filesz / entsize is
+ non-zero.
+
2021-12-08 Mark Wielaard <mark@klomp.org>
* dwfl_segment_report_module.c (dwfl_segment_report_module): Add
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 82df7b69..177ad9a5 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -1017,6 +1017,11 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
in.d_size. The data might have been truncated. */
if (dyn_filesz > in.d_size)
dyn_filesz = in.d_size;
+ if (dyn_filesz / entsize == 0)
+ {
+ __libdwfl_seterrno (DWFL_E_BADELF);
+ return false;
+ }
void *buf = malloc (dyn_filesz);
Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = buf;
Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = buf;
--
2.30.2
reply other threads:[~2021-12-17 21:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20211217215657.776086-1-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).