Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: Re: [rfc] Detect dwarf address size mismatch
Date: Tue, 17 Jul 2007 12:52:00 -0000	[thread overview]
Message-ID: <20070717124711.GA27936@caradoc.them.org> (raw)
In-Reply-To: <m3hcoabs3r.fsf@codesourcery.com>

On Wed, Jul 11, 2007 at 01:30:48PM -0700, Jim Blandy wrote:
> True.  But I think the check should go after the switch in any case;
> there's no reason to only apply sanity checking to that one opcode.

Reasonable enough.  I've checked in this version.

-- 
Daniel Jacobowitz
CodeSourcery

2007-07-17  Daniel Jacobowitz  <dan@codesourcery.com>

	* dwarf2read.c (dwarf_decode_lines): Detect address size mismatches.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.227
diff -u -p -r1.227 dwarf2read.c
--- dwarf2read.c	22 Jun 2007 12:26:59 -0000	1.227
+++ dwarf2read.c	17 Jul 2007 12:45:22 -0000
@@ -6668,9 +6668,9 @@ static void
 dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
 		    struct dwarf2_cu *cu, struct partial_symtab *pst)
 {
-  gdb_byte *line_ptr;
+  gdb_byte *line_ptr, *extended_end;
   gdb_byte *line_end;
-  unsigned int bytes_read;
+  unsigned int bytes_read, extended_len;
   unsigned char op_code, extended_op, adj_opcode;
   CORE_ADDR baseaddr;
   struct objfile *objfile = cu->objfile;
@@ -6745,8 +6745,9 @@ dwarf_decode_lines (struct line_header *
 	  else switch (op_code)
 	    {
 	    case DW_LNS_extended_op:
-	      read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
+	      extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
 	      line_ptr += bytes_read;
+	      extended_end = line_ptr + extended_len;
 	      extended_op = read_1_byte (abfd, line_ptr);
 	      line_ptr += 1;
 	      switch (extended_op)
@@ -6792,6 +6793,15 @@ dwarf_decode_lines (struct line_header *
 			     _("mangled .debug_line section"));
 		  return;
 		}
+	      /* Make sure that we parsed the extended op correctly.  If e.g.
+		 we expected a different address size than the producer used,
+		 we may have read the wrong number of bytes.  */
+	      if (line_ptr != extended_end)
+		{
+		  complaint (&symfile_complaints,
+			     _("mangled .debug_line section"));
+		  return;
+		}
 	      break;
 	    case DW_LNS_copy:
 	      if (lh->num_file_names < file)


  reply	other threads:[~2007-07-17 12:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-11 14:19 Daniel Jacobowitz
2007-07-11 19:23 ` Eli Zaretskii
2007-07-11 19:27 ` Jim Blandy
2007-07-11 19:41   ` Daniel Jacobowitz
2007-07-11 20:30     ` Jim Blandy
2007-07-17 12:52       ` Daniel Jacobowitz [this message]
2007-07-17 13:21         ` Mark Kettenis
2007-07-17 13:55           ` Daniel Jacobowitz

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=20070717124711.GA27936@caradoc.them.org \
    --to=drow@false.org \
    --cc=gdb-patches@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