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: [PATCH] libdw: Explicitly check we could decode diridx in dwarf_getsrclines.
Date: Tue, 05 Jun 2018 21:36:00 -0000	[thread overview]
Message-ID: <1528234602-32214-1-git-send-email-mark@klomp.org> (raw)

It is highly unlikely dwarf_formudata fails because we setup the attribute
ourselves, but better to explicitly mark diridx as bad if it does.

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

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 661fa9d..21adeb7 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,10 @@
 2018-06-05  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf_getsrclines.c (read_srclines): Explicitly set diridx to -1
+	in case dwarf_formudata fails.
+
+2018-06-05  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf_getaranges (dwarf_getaranges): Free new_arange if
 	__libdw_findcu fails.
 
diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index 0c2efaa..07baebc 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -566,7 +566,7 @@ read_srclines (Dwarf *dbg,
       for (unsigned int n = 0; n < nfiles; n++)
 	{
 	  const char *fname = NULL;
-	  Dwarf_Word diridx = -1;
+	  Dwarf_Word diridx = (Dwarf_Word) -1;
 	  for (unsigned char m = 0; m < nforms; m++)
 	    {
 	      if (m == form_path)
@@ -581,7 +581,8 @@ read_srclines (Dwarf *dbg,
 		  attr.code = DW_AT_decl_file; /* Close enough.  */
 		  attr.form = forms[m];
 		  attr.valp = (void *) linep;
-		  dwarf_formudata (&attr, &diridx);
+		  if (dwarf_formudata (&attr, &diridx) != 0)
+		    diridx = (Dwarf_Word) -1;
 		}
 
 	      size_t len = __libdw_form_val_len (&fake_cu, forms[m], linep);
-- 
1.8.3.1

             reply	other threads:[~2018-06-05 21:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 21:36 Mark Wielaard [this message]
2018-06-08 10:09 ` 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=1528234602-32214-1-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).