public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jon TURNEY <jon.turney@dronecode.org.uk>
To: binutils@sourceware.org
Cc: Jon TURNEY <jon.turney@dronecode.org.uk>
Subject: [PATCH 1/2] pe/coff: Avoid a crash using objdump -p on the output of objcopy --only-keep-debug
Date: Tue, 18 Mar 2014 14:39:00 -0000	[thread overview]
Message-ID: <1395153555-5572-2-git-send-email-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <1395153555-5572-1-git-send-email-jon.turney@dronecode.org.uk>

Avoid a crash when using objdump -p on the output of objcopy --only-keep-debug

e.g.

$ objdump -p /usr/lib/debug/usr/bin/cygwin1.dbg
[...]
The Export Tables (interpreted .edata section contents)

Export Flags                    0
Time/Date stamp                 0
Major/Minor                     0/0
Segmentation fault (core dumped)

Verfify that edt.name lies inside the .edata section we have loaded before
dereferencing it.  Change adj to to bfd_vma to avoid signed vs. unsigned
comparison warnings - it could only be negative if a section had a negative
vma.

bfd/Changelog:

2014-03-18  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* peXXigen.c (pe_print_edata): Verify edt.name lies inside
	section before dereferencing.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 bfd/peXXigen.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 8219ab9..d011c0e 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -1373,7 +1373,7 @@ pe_print_edata (bfd * abfd, void * vfile)
   bfd_size_type datasize = 0;
   bfd_size_type dataoff;
   bfd_size_type i;
-  bfd_signed_vma adj;
+  bfd_vma adj;
   struct EDT_type
   {
     long export_flags;          /* Reserved - should be zero.  */
@@ -1478,8 +1478,12 @@ pe_print_edata (bfd * abfd, void * vfile)
   fprintf (file,
 	   _("Name \t\t\t\t"));
   bfd_fprintf_vma (abfd, file, edt.name);
-  fprintf (file,
+
+  if ((edt.name >= adj) && (edt.name < adj + datasize))
+    fprintf (file,
 	   " %s\n", data + edt.name - adj);
+  else
+    fprintf (file, "(outside .edata section)\n");
 
   fprintf (file,
 	   _("Ordinal Base \t\t\t%ld\n"), edt.base);
-- 
1.8.3.4

  reply	other threads:[~2014-03-18 14:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18 14:39 [PATCH 0/2] pe/coff: Improve 'objdump -p' handling of the output of 'objcopy --only-keep-debug' Jon TURNEY
2014-03-18 14:39 ` Jon TURNEY [this message]
2014-04-03  4:02   ` [PATCH 1/2] pe/coff: Avoid a crash using objdump -p on the output of objcopy --only-keep-debug Christopher Faylor
2014-04-03 11:28     ` Nicholas Clifton
2014-04-04 14:47       ` Jon TURNEY
2014-04-08 10:04         ` Nicholas Clifton
2014-04-08 18:40           ` Jon TURNEY
2014-04-09  4:37             ` Alan Modra
2014-03-18 14:39 ` [PATCH 2/2] pe/coff: Don't try to interpret the contents of sections with no contents for 'objdump -p' Jon TURNEY

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=1395153555-5572-2-git-send-email-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=binutils@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).