Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: gdb-patches@sourceware.org
Subject: Fix gdb crash during .debug_line parsing
Date: Wed, 05 Nov 2008 12:53:00 -0000	[thread overview]
Message-ID: <jefxm6bahk.fsf@sykes.suse.de> (raw)

gdb should not crash when the line number program has been corrupted.

Andreas.

2008-11-05  Andreas Schwab  <schwab@suse.de>

	* dwarf2read.c (dwarf_decode_lines): Add checks for corrupted line
	number programs.

Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.290
diff -u -a -p -u -p -a -r1.290 dwarf2read.c
--- dwarf2read.c	24 Oct 2008 18:21:00 -0000	1.290
+++ dwarf2read.c	5 Nov 2008 12:44:15 -0000
@@ -7072,7 +7072,7 @@ dwarf_decode_lines (struct line_header *
       int basic_block = 0;
       int end_sequence = 0;
 
-      if (!decode_for_pst_p && lh->num_file_names >= file)
+      if (!decode_for_pst_p && file != 0 && lh->num_file_names >= file)
 	{
           /* Start a subfile for the current file of the state machine.  */
 	  /* lh->include_dirs and lh->file_names are 0-based, but the
@@ -7090,6 +7090,13 @@ dwarf_decode_lines (struct line_header *
       /* Decode the table.  */
       while (!end_sequence)
 	{
+	  if (line_ptr >= line_end)
+	    {
+	      complaint (&symfile_complaints,
+			 _("mangled .debug_line section"));
+	      break;
+	    }
+
 	  op_code = read_1_byte (abfd, line_ptr);
 	  line_ptr += 1;
 
@@ -7102,7 +7109,7 @@ dwarf_decode_lines (struct line_header *
 	      line += lh->line_base + (adj_opcode % lh->line_range);
 	      if (lh->num_file_names < file)
 		dwarf2_debug_line_missing_file_complaint ();
-	      else
+	      else if (file != 0)
 		{
 		  lh->file_names[file - 1].included_p = 1;
 		  if (!decode_for_pst_p)
@@ -7135,7 +7142,7 @@ dwarf_decode_lines (struct line_header *
 
 		  if (lh->num_file_names < file)
 		    dwarf2_debug_line_missing_file_complaint ();
-		  else
+		  else if (file != 0)
 		    {
 		      lh->file_names[file - 1].included_p = 1;
 		      if (!decode_for_pst_p)
@@ -7184,7 +7191,7 @@ dwarf_decode_lines (struct line_header *
 	    case DW_LNS_copy:
 	      if (lh->num_file_names < file)
 		dwarf2_debug_line_missing_file_complaint ();
-	      else
+	      else if (file != 0)
 		{
 		  lh->file_names[file - 1].included_p = 1;
 		  if (!decode_for_pst_p)
@@ -7220,7 +7227,7 @@ dwarf_decode_lines (struct line_header *
 
                 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
                 line_ptr += bytes_read;
-                if (lh->num_file_names < file)
+		if (file == 0 || lh->num_file_names < file)
                   dwarf2_debug_line_missing_file_complaint ();
                 else
                   {

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


             reply	other threads:[~2008-11-05 12:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-05 12:53 Andreas Schwab [this message]
2008-11-09 17:25 ` Joel Brobecker
2008-11-09 18:32   ` Andreas Schwab
2008-11-10 19:05   ` Joel Brobecker
2008-11-16  8:18   ` Joel Brobecker

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=jefxm6bahk.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --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