public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [COMMITTED] libdw: Don't pass NULL to dwarf_peel_type
Date: Mon, 18 Oct 2021 14:40:35 +0200	[thread overview]
Message-ID: <20211018124035.23055-1-mark@klomp.org> (raw)

commit c3a6a9dfc "libdw: Use signedness of subrange type to
determine array bounds" introduced a type check on a DIE which
exposed a latent bug in the get_type function. Even if the type
of a DIE couldn't be determined it would call dwarf_peel_type
on it. The gcc undefined sanitizer would flag this as being
undefined behaviour because the second argument of the function
is marked as non-NULL. Fix this by checking we actually have
a non-NULL type DIE.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdw/ChangeLog              | 5 +++++
 libdw/dwarf_aggregate_size.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4275b830..311f34b5 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2021-10-18  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf_aggregate_size.c (get_type): Don't pass NULL to
+	dwarf_peel_type.
+
 2021-10-06  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf_aggregate_size.c (array_size): Check signedness of child DIE
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
index 96023d69..89f2029e 100644
--- a/libdw/dwarf_aggregate_size.c
+++ b/libdw/dwarf_aggregate_size.c
@@ -40,7 +40,7 @@ get_type (Dwarf_Die *die, Dwarf_Attribute *attr_mem, Dwarf_Die *type_mem)
   Dwarf_Die *type = INTUSE(dwarf_formref_die)
     (INTUSE(dwarf_attr_integrate) (die, DW_AT_type, attr_mem), type_mem);
 
-  if (INTUSE(dwarf_peel_type) (type, type) != 0)
+  if (type == NULL || INTUSE(dwarf_peel_type) (type, type) != 0)
     return NULL;
 
   return type;
-- 
2.18.4


                 reply	other threads:[~2021-10-18 12:40 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=20211018124035.23055-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).