From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH 1/2] libdw: Make sure that address_size and offset_size are 4 or 8 bytes.
Date: Thu, 07 Jun 2018 21:45:00 -0000 [thread overview]
Message-ID: <1528407882-16903-2-git-send-email-mark@klomp.org> (raw)
In-Reply-To: <1528407882-16903-1-git-send-email-mark@klomp.org>
When interning a CU make sure that address_size and offset_size are
either 4 or 8 bytes. We really don't (want to) handle any other size.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libdw/ChangeLog | 6 ++++++
libdw/libdw_findcu.c | 13 +++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index b569393..9d0b484 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,9 @@
+2018-06-07 Mark Wielaard <mark@klomp.org>
+
+ * libdw_findcu.c (__libdw_intern_next_unit): Report DWARF_E_VERSION,
+ not DWARF_E_INVALID_DWARF on unknown version. Set address_size and
+ offset_size to 8 when unknown.
+
2018-06-06 Mark Wielaard <mark@klomp.org>
* libdwP.h (__libdw_dieabbrev): Check DIE addr falls in cu.
diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
index 2f5c6c4..ed74423 100644
--- a/libdw/libdw_findcu.c
+++ b/libdw/libdw_findcu.c
@@ -120,14 +120,23 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
return NULL;
/* We only know how to handle the DWARF version 2 through 5 formats.
- For v4 debug types we only handle version 4. */
+ For v4 debug types we only handle version 4. */
if (unlikely (version < 2) || unlikely (version > 5)
|| (debug_types && unlikely (version != 4)))
{
- __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ __libdw_seterrno (DWARF_E_VERSION);
return NULL;
}
+ /* We only handle 32 or 64 bit (4 or 8 byte) addresses and offsets.
+ Just assume we are dealing with 64bit in case the size is "unknown".
+ Too much code assumes if it isn't 4 then it is 8 (or the other way
+ around). */
+ if (unlikely (address_size != 4 && address_size != 8))
+ address_size = 8;
+ if (unlikely (offset_size != 4 && offset_size != 8))
+ offset_size = 8;
+
/* Invalid or truncated debug section data? */
size_t sec_idx = debug_types ? IDX_debug_types : IDX_debug_info;
Elf_Data *data = dbg->sectiondata[sec_idx];
--
1.8.3.1
next prev parent reply other threads:[~2018-06-07 21:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 17:05 [PATCH] readelf: Don't allocate string with asprintf, but reuse buffer with sprintf Mark Wielaard
2018-06-06 20:37 ` Mark Wielaard
2018-06-07 21:44 ` Mark Wielaard
2018-06-07 21:45 ` Mark Wielaard [this message]
2018-06-09 8:35 ` [PATCH 1/2] libdw: Make sure that address_size and offset_size are 4 or 8 bytes Mark Wielaard
2018-06-07 21:46 ` [PATCH 2/2] readelf: Turn format_print_dwarf into print_dwarf_addr Mark Wielaard
2018-06-09 8:38 ` 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=1528407882-16903-2-git-send-email-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).